12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745 |
- goog.provide('goog.date');
- goog.provide('goog.date.Date');
- goog.provide('goog.date.DateTime');
- goog.provide('goog.date.Interval');
- goog.provide('goog.date.month');
- goog.provide('goog.date.weekDay');
- goog.require('goog.asserts');
- goog.require('goog.date.DateLike');
- goog.require('goog.i18n.DateTimeSymbols');
- goog.require('goog.string');
- goog.date.weekDay = {
- MON: 0,
- TUE: 1,
- WED: 2,
- THU: 3,
- FRI: 4,
- SAT: 5,
- SUN: 6
- };
- goog.date.month = {
- JAN: 0,
- FEB: 1,
- MAR: 2,
- APR: 3,
- MAY: 4,
- JUN: 5,
- JUL: 6,
- AUG: 7,
- SEP: 8,
- OCT: 9,
- NOV: 10,
- DEC: 11
- };
- goog.date.formatMonthAndYear = function(monthName, yearNum) {
-
- var MSG_MONTH_AND_YEAR = goog.getMsg(
- '{$monthName} {$yearNum}',
- {'monthName': monthName, 'yearNum': String(yearNum)});
- return MSG_MONTH_AND_YEAR;
- };
- goog.date.splitDateStringRegex_ = new RegExp(
- '^(\\d{4})(?:(?:-?(\\d{2})(?:-?(\\d{2}))?)|' +
- '(?:-?(\\d{3}))|(?:-?W(\\d{2})(?:-?([1-7]))?))?$');
- goog.date.splitTimeStringRegex_ =
- /^(\d{2})(?::?(\d{2})(?::?(\d{2})(\.\d+)?)?)?$/;
- goog.date.splitTimezoneStringRegex_ = /Z|(?:([-+])(\d{2})(?::?(\d{2}))?)$/;
- goog.date.splitDurationRegex_ = new RegExp(
- '^(-)?P(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)D)?' +
- '(T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+(?:\\.\\d+)?)S)?)?$');
- goog.date.MS_PER_DAY = 24 * 60 * 60 * 1000;
- goog.date.isLeapYear = function(year) {
-
- return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
- };
- goog.date.isLongIsoYear = function(year) {
- var n = 5 * year + 12 - 4 * (Math.floor(year / 100) - Math.floor(year / 400));
- n += Math.floor((year - 100) / 400) - Math.floor((year - 102) / 400);
- n += Math.floor((year - 200) / 400) - Math.floor((year - 199) / 400);
- return n % 28 < 5;
- };
- goog.date.getNumberOfDaysInMonth = function(year, month) {
- switch (month) {
- case goog.date.month.FEB:
- return goog.date.isLeapYear(year) ? 29 : 28;
- case goog.date.month.JUN:
- case goog.date.month.SEP:
- case goog.date.month.NOV:
- case goog.date.month.APR:
- return 30;
- }
- return 31;
- };
- goog.date.isSameDay = function(date, opt_now) {
- var now = opt_now || new Date(goog.now());
- return date.getDate() == now.getDate() && goog.date.isSameMonth(date, now);
- };
- goog.date.isSameMonth = function(date, opt_now) {
- var now = opt_now || new Date(goog.now());
- return date.getMonth() == now.getMonth() && goog.date.isSameYear(date, now);
- };
- goog.date.isSameYear = function(date, opt_now) {
- var now = opt_now || new Date(goog.now());
- return date.getFullYear() == now.getFullYear();
- };
- goog.date.getWeekNumber = function(
- year, month, date, opt_weekDay, opt_firstDayOfWeek) {
- var d = new Date(year, month, date);
-
- var cutoff = goog.isDef(opt_weekDay) ? opt_weekDay : goog.date.weekDay.THU;
-
- var firstday = opt_firstDayOfWeek || goog.date.weekDay.MON;
-
- var isoday = (d.getDay() + 6) % 7;
-
- var daypos = (isoday - firstday + 7) % 7;
-
- var cutoffpos = (cutoff - firstday + 7) % 7;
-
-
-
- var cutoffSameWeek =
- d.valueOf() + (cutoffpos - daypos) * goog.date.MS_PER_DAY;
-
- var jan1 = new Date(new Date(cutoffSameWeek).getFullYear(), 0, 1).valueOf();
-
- return Math.floor(
- Math.round((cutoffSameWeek - jan1) / goog.date.MS_PER_DAY) / 7) +
- 1;
- };
- goog.date.min = function(date1, date2) {
- return date1 < date2 ? date1 : date2;
- };
- goog.date.max = function(date1, date2) {
- return date1 > date2 ? date1 : date2;
- };
- goog.date.fromIsoString = function(formatted) {
- var ret = new goog.date.DateTime(2000);
- return goog.date.setIso8601DateTime(ret, formatted) ? ret : null;
- };
- goog.date.setIso8601DateTime = function(dateTime, formatted) {
- formatted = goog.string.trim(formatted);
- var delim = formatted.indexOf('T') == -1 ? ' ' : 'T';
- var parts = formatted.split(delim);
- return goog.date.setIso8601DateOnly_(dateTime, parts[0]) &&
- (parts.length < 2 || goog.date.setIso8601TimeOnly_(dateTime, parts[1]));
- };
- goog.date.setIso8601DateOnly_ = function(d, formatted) {
-
- var parts = formatted.match(goog.date.splitDateStringRegex_);
- if (!parts) {
- return false;
- }
- var year = Number(parts[1]);
- var month = Number(parts[2]);
- var date = Number(parts[3]);
- var dayOfYear = Number(parts[4]);
- var week = Number(parts[5]);
-
- var dayOfWeek = Number(parts[6]) || 1;
- d.setFullYear(year);
- if (dayOfYear) {
- d.setDate(1);
- d.setMonth(0);
- var offset = dayOfYear - 1;
- d.add(new goog.date.Interval(goog.date.Interval.DAYS, offset));
- } else if (week) {
- goog.date.setDateFromIso8601Week_(d, week, dayOfWeek);
- } else {
- if (month) {
- d.setDate(1);
- d.setMonth(month - 1);
- }
- if (date) {
- d.setDate(date);
- }
- }
- return true;
- };
- goog.date.setDateFromIso8601Week_ = function(d, week, dayOfWeek) {
-
- d.setMonth(0);
- d.setDate(1);
- var jsDay = d.getDay();
-
- var jan1WeekDay = jsDay || 7;
- var THURSDAY = 4;
- if (jan1WeekDay <= THURSDAY) {
-
- var startDelta = 1 - jan1WeekDay;
- } else {
-
- startDelta = 8 - jan1WeekDay;
- }
-
-
-
-
- var absoluteDays = Number(dayOfWeek) + (7 * (Number(week) - 1));
-
-
- var delta = startDelta + absoluteDays - 1;
- var interval = new goog.date.Interval(goog.date.Interval.DAYS, delta);
- d.add(interval);
- };
- goog.date.setIso8601TimeOnly_ = function(d, formatted) {
-
- var parts = formatted.match(goog.date.splitTimezoneStringRegex_);
- var offset = 0;
- if (parts) {
- if (parts[0] != 'Z') {
- offset = Number(parts[2]) * 60 + Number(parts[3]);
- offset *= parts[1] == '-' ? 1 : -1;
- }
- offset -= d.getTimezoneOffset();
- formatted = formatted.substr(0, formatted.length - parts[0].length);
- }
-
- parts = formatted.match(goog.date.splitTimeStringRegex_);
- if (!parts) {
- return false;
- }
- d.setHours(Number(parts[1]));
- d.setMinutes(Number(parts[2]) || 0);
- d.setSeconds(Number(parts[3]) || 0);
- d.setMilliseconds(parts[4] ? Number(parts[4]) * 1000 : 0);
- if (offset != 0) {
-
- d.setTime(d.getTime() + offset * 60000);
- }
- return true;
- };
- goog.date.Interval = function(
- opt_years, opt_months, opt_days, opt_hours, opt_minutes, opt_seconds) {
- if (goog.isString(opt_years)) {
- var type = opt_years;
- var interval = (opt_months);
- this.years = type == goog.date.Interval.YEARS ? interval : 0;
- this.months = type == goog.date.Interval.MONTHS ? interval : 0;
- this.days = type == goog.date.Interval.DAYS ? interval : 0;
- this.hours = type == goog.date.Interval.HOURS ? interval : 0;
- this.minutes = type == goog.date.Interval.MINUTES ? interval : 0;
- this.seconds = type == goog.date.Interval.SECONDS ? interval : 0;
- } else {
- this.years = (opt_years) || 0;
- this.months = opt_months || 0;
- this.days = opt_days || 0;
- this.hours = opt_hours || 0;
- this.minutes = opt_minutes || 0;
- this.seconds = opt_seconds || 0;
- }
- };
- goog.date.Interval.fromIsoString = function(duration) {
- var parts = duration.match(goog.date.splitDurationRegex_);
- if (!parts) {
- return null;
- }
- var timeEmpty = !(parts[6] || parts[7] || parts[8]);
- var dateTimeEmpty = timeEmpty && !(parts[2] || parts[3] || parts[4]);
- if (dateTimeEmpty || timeEmpty && parts[5]) {
- return null;
- }
- var negative = parts[1];
- var years = parseInt(parts[2], 10) || 0;
- var months = parseInt(parts[3], 10) || 0;
- var days = parseInt(parts[4], 10) || 0;
- var hours = parseInt(parts[6], 10) || 0;
- var minutes = parseInt(parts[7], 10) || 0;
- var seconds = parseFloat(parts[8]) || 0;
- return negative ?
- new goog.date.Interval(
- -years, -months, -days, -hours, -minutes, -seconds) :
- new goog.date.Interval(years, months, days, hours, minutes, seconds);
- };
- goog.date.Interval.prototype.toIsoString = function(opt_verbose) {
- var minField = Math.min(
- this.years, this.months, this.days, this.hours, this.minutes,
- this.seconds);
- var maxField = Math.max(
- this.years, this.months, this.days, this.hours, this.minutes,
- this.seconds);
- if (minField < 0 && maxField > 0) {
- return null;
- }
-
- if (!opt_verbose && minField == 0 && maxField == 0) {
- return 'PT0S';
- }
- var res = [];
-
- if (minField < 0) {
- res.push('-');
- }
- res.push('P');
-
- if (this.years || opt_verbose) {
- res.push(Math.abs(this.years) + 'Y');
- }
- if (this.months || opt_verbose) {
- res.push(Math.abs(this.months) + 'M');
- }
- if (this.days || opt_verbose) {
- res.push(Math.abs(this.days) + 'D');
- }
-
- if (this.hours || this.minutes || this.seconds || opt_verbose) {
- res.push('T');
- if (this.hours || opt_verbose) {
- res.push(Math.abs(this.hours) + 'H');
- }
- if (this.minutes || opt_verbose) {
- res.push(Math.abs(this.minutes) + 'M');
- }
- if (this.seconds || opt_verbose) {
- res.push(Math.abs(this.seconds) + 'S');
- }
- }
- return res.join('');
- };
- goog.date.Interval.prototype.equals = function(other) {
- return other.years == this.years && other.months == this.months &&
- other.days == this.days && other.hours == this.hours &&
- other.minutes == this.minutes && other.seconds == this.seconds;
- };
- goog.date.Interval.prototype.clone = function() {
- return new goog.date.Interval(
- this.years, this.months, this.days, this.hours, this.minutes,
- this.seconds);
- };
- goog.date.Interval.YEARS = 'y';
- goog.date.Interval.MONTHS = 'm';
- goog.date.Interval.DAYS = 'd';
- goog.date.Interval.HOURS = 'h';
- goog.date.Interval.MINUTES = 'n';
- goog.date.Interval.SECONDS = 's';
- goog.date.Interval.prototype.isZero = function() {
- return this.years == 0 && this.months == 0 && this.days == 0 &&
- this.hours == 0 && this.minutes == 0 && this.seconds == 0;
- };
- goog.date.Interval.prototype.getInverse = function() {
- return this.times(-1);
- };
- goog.date.Interval.prototype.times = function(n) {
- return new goog.date.Interval(
- this.years * n, this.months * n, this.days * n, this.hours * n,
- this.minutes * n, this.seconds * n);
- };
- goog.date.Interval.prototype.getTotalSeconds = function() {
- goog.asserts.assert(this.years == 0 && this.months == 0);
- return ((this.days * 24 + this.hours) * 60 + this.minutes) * 60 +
- this.seconds;
- };
- goog.date.Interval.prototype.add = function(interval) {
- this.years += interval.years;
- this.months += interval.months;
- this.days += interval.days;
- this.hours += interval.hours;
- this.minutes += interval.minutes;
- this.seconds += interval.seconds;
- };
- goog.date.Date = function(opt_year, opt_month, opt_date) {
-
- this.date;
-
- if (goog.isNumber(opt_year)) {
- this.date = this.buildDate_(opt_year, opt_month || 0, opt_date || 1);
- this.maybeFixDst_(opt_date || 1);
- } else if (goog.isObject(opt_year)) {
- this.date = this.buildDate_(
- opt_year.getFullYear(), opt_year.getMonth(), opt_year.getDate());
- this.maybeFixDst_(opt_year.getDate());
- } else {
- this.date = new Date(goog.now());
- var expectedDate = this.date.getDate();
- this.date.setHours(0);
- this.date.setMinutes(0);
- this.date.setSeconds(0);
- this.date.setMilliseconds(0);
-
-
-
- this.maybeFixDst_(expectedDate);
- }
- };
- goog.date.Date.prototype.buildDate_ = function(fullYear, month, date) {
- var d = new Date(fullYear, month, date);
- if (fullYear >= 0 && fullYear < 100) {
-
- d.setFullYear(d.getFullYear() - 1900);
- }
- return d;
- };
- goog.date.Date.prototype.firstDayOfWeek_ =
- goog.i18n.DateTimeSymbols.FIRSTDAYOFWEEK;
- goog.date.Date.prototype.firstWeekCutOffDay_ =
- goog.i18n.DateTimeSymbols.FIRSTWEEKCUTOFFDAY;
- goog.date.Date.prototype.clone = function() {
- var date = new goog.date.Date(this.date);
- date.firstDayOfWeek_ = this.firstDayOfWeek_;
- date.firstWeekCutOffDay_ = this.firstWeekCutOffDay_;
- return date;
- };
- goog.date.Date.prototype.getFullYear = function() {
- return this.date.getFullYear();
- };
- goog.date.Date.prototype.getYear = function() {
- return this.getFullYear();
- };
- goog.date.Date.prototype.getMonth = function() {
- return (this.date.getMonth());
- };
- goog.date.Date.prototype.getDate = function() {
- return this.date.getDate();
- };
- goog.date.Date.prototype.getTime = function() {
- return this.date.getTime();
- };
- goog.date.Date.prototype.getDay = function() {
- return this.date.getDay();
- };
- goog.date.Date.prototype.getIsoWeekday = function() {
- return ((this.getDay() + 6) % 7);
- };
- goog.date.Date.prototype.getWeekday = function() {
- return (this.getIsoWeekday() - this.firstDayOfWeek_ + 7) % 7;
- };
- goog.date.Date.prototype.getUTCFullYear = function() {
- return this.date.getUTCFullYear();
- };
- goog.date.Date.prototype.getUTCMonth = function() {
- return (this.date.getUTCMonth());
- };
- goog.date.Date.prototype.getUTCDate = function() {
- return this.date.getUTCDate();
- };
- goog.date.Date.prototype.getUTCDay = function() {
- return this.date.getDay();
- };
- goog.date.Date.prototype.getUTCHours = function() {
- return this.date.getUTCHours();
- };
- goog.date.Date.prototype.getUTCMinutes = function() {
- return this.date.getUTCMinutes();
- };
- goog.date.Date.prototype.getUTCIsoWeekday = function() {
- return ((this.date.getUTCDay() + 6) % 7);
- };
- goog.date.Date.prototype.getUTCWeekday = function() {
- return (this.getUTCIsoWeekday() - this.firstDayOfWeek_ + 7) % 7;
- };
- goog.date.Date.prototype.getFirstDayOfWeek = function() {
- return this.firstDayOfWeek_;
- };
- goog.date.Date.prototype.getFirstWeekCutOffDay = function() {
- return this.firstWeekCutOffDay_;
- };
- goog.date.Date.prototype.getNumberOfDaysInMonth = function() {
- return goog.date.getNumberOfDaysInMonth(this.getFullYear(), this.getMonth());
- };
- goog.date.Date.prototype.getWeekNumber = function() {
- return goog.date.getWeekNumber(
- this.getFullYear(), this.getMonth(), this.getDate(),
- this.firstWeekCutOffDay_, this.firstDayOfWeek_);
- };
- goog.date.Date.prototype.getDayOfYear = function() {
- var dayOfYear = this.getDate();
- var year = this.getFullYear();
- for (var m = this.getMonth() - 1; m >= 0; m--) {
- dayOfYear += goog.date.getNumberOfDaysInMonth(year, m);
- }
- return dayOfYear;
- };
- goog.date.Date.prototype.getTimezoneOffset = function() {
- return this.date.getTimezoneOffset();
- };
- goog.date.Date.prototype.getTimezoneOffsetString = function() {
- var tz;
- var offset = this.getTimezoneOffset();
- if (offset == 0) {
- tz = 'Z';
- } else {
- var n = Math.abs(offset) / 60;
- var h = Math.floor(n);
- var m = (n - h) * 60;
- tz = (offset > 0 ? '-' : '+') + goog.string.padNumber(h, 2) + ':' +
- goog.string.padNumber(m, 2);
- }
- return tz;
- };
- goog.date.Date.prototype.set = function(date) {
- this.date = new Date(date.getFullYear(), date.getMonth(), date.getDate());
- };
- goog.date.Date.prototype.setFullYear = function(year) {
- this.date.setFullYear(year);
- };
- goog.date.Date.prototype.setYear = function(year) {
- this.setFullYear(year);
- };
- goog.date.Date.prototype.setMonth = function(month) {
- this.date.setMonth(month);
- };
- goog.date.Date.prototype.setDate = function(date) {
- this.date.setDate(date);
- };
- goog.date.Date.prototype.setTime = function(ms) {
- this.date.setTime(ms);
- };
- goog.date.Date.prototype.setUTCFullYear = function(year) {
- this.date.setUTCFullYear(year);
- };
- goog.date.Date.prototype.setUTCMonth = function(month) {
- this.date.setUTCMonth(month);
- };
- goog.date.Date.prototype.setUTCDate = function(date) {
- this.date.setUTCDate(date);
- };
- goog.date.Date.prototype.setFirstDayOfWeek = function(day) {
- this.firstDayOfWeek_ = day;
- };
- goog.date.Date.prototype.setFirstWeekCutOffDay = function(day) {
- this.firstWeekCutOffDay_ = day;
- };
- goog.date.Date.prototype.add = function(interval) {
- if (interval.years || interval.months) {
-
-
-
-
- var month = this.getMonth() + interval.months + interval.years * 12;
- var year = this.getYear() + Math.floor(month / 12);
- month %= 12;
- if (month < 0) {
- month += 12;
- }
- var daysInTargetMonth = goog.date.getNumberOfDaysInMonth(year, month);
- var date = Math.min(daysInTargetMonth, this.getDate());
-
- this.setDate(1);
- this.setFullYear(year);
- this.setMonth(month);
- this.setDate(date);
- }
- if (interval.days) {
-
-
- var noon = new Date(this.getYear(), this.getMonth(), this.getDate(), 12);
- var result = new Date(noon.getTime() + interval.days * 86400000);
-
- this.setDate(1);
- this.setFullYear(result.getFullYear());
- this.setMonth(result.getMonth());
- this.setDate(result.getDate());
- this.maybeFixDst_(result.getDate());
- }
- };
- goog.date.Date.prototype.toIsoString = function(opt_verbose, opt_tz) {
- var str = [
- this.getFullYear(), goog.string.padNumber(this.getMonth() + 1, 2),
- goog.string.padNumber(this.getDate(), 2)
- ];
- return str.join((opt_verbose) ? '-' : '') +
- (opt_tz ? this.getTimezoneOffsetString() : '');
- };
- goog.date.Date.prototype.toUTCIsoString = function(opt_verbose, opt_tz) {
- var str = [
- this.getUTCFullYear(), goog.string.padNumber(this.getUTCMonth() + 1, 2),
- goog.string.padNumber(this.getUTCDate(), 2)
- ];
- return str.join((opt_verbose) ? '-' : '') + (opt_tz ? 'Z' : '');
- };
- goog.date.Date.prototype.equals = function(other) {
- return !!(
- other && this.getYear() == other.getYear() &&
- this.getMonth() == other.getMonth() && this.getDate() == other.getDate());
- };
- goog.date.Date.prototype.toString = function() {
- return this.toIsoString();
- };
- goog.date.Date.prototype.maybeFixDst_ = function(expected) {
- if (this.getDate() != expected) {
- var dir = this.getDate() < expected ? 1 : -1;
- this.date.setUTCHours(this.date.getUTCHours() + dir);
- }
- };
- goog.date.Date.prototype.valueOf = function() {
- return this.date.valueOf();
- };
- goog.date.Date.compare = function(date1, date2) {
- return date1.getTime() - date2.getTime();
- };
- goog.date.DateTime = function(
- opt_year, opt_month, opt_date, opt_hours, opt_minutes, opt_seconds,
- opt_milliseconds) {
- if (goog.isNumber(opt_year)) {
- this.date = new Date(
- opt_year, opt_month || 0, opt_date || 1, opt_hours || 0,
- opt_minutes || 0, opt_seconds || 0, opt_milliseconds || 0);
- } else {
- this.date = new Date(
- opt_year && opt_year.getTime ? opt_year.getTime() : goog.now());
- }
- };
- goog.inherits(goog.date.DateTime, goog.date.Date);
- goog.date.DateTime.fromTimestamp = function(timestamp) {
- var date = new goog.date.DateTime();
- date.setTime(timestamp);
- return date;
- };
- goog.date.DateTime.fromRfc822String = function(formatted) {
- var date = new Date(formatted);
- return !isNaN(date.getTime()) ? new goog.date.DateTime(date) : null;
- };
- goog.date.DateTime.prototype.getHours = function() {
- return this.date.getHours();
- };
- goog.date.DateTime.prototype.getMinutes = function() {
- return this.date.getMinutes();
- };
- goog.date.DateTime.prototype.getSeconds = function() {
- return this.date.getSeconds();
- };
- goog.date.DateTime.prototype.getMilliseconds = function() {
- return this.date.getMilliseconds();
- };
- goog.date.DateTime.prototype.getUTCDay = function() {
- return (this.date.getUTCDay());
- };
- goog.date.DateTime.prototype.getUTCHours = function() {
- return this.date.getUTCHours();
- };
- goog.date.DateTime.prototype.getUTCMinutes = function() {
- return this.date.getUTCMinutes();
- };
- goog.date.DateTime.prototype.getUTCSeconds = function() {
- return this.date.getUTCSeconds();
- };
- goog.date.DateTime.prototype.getUTCMilliseconds = function() {
- return this.date.getUTCMilliseconds();
- };
- goog.date.DateTime.prototype.setHours = function(hours) {
- this.date.setHours(hours);
- };
- goog.date.DateTime.prototype.setMinutes = function(minutes) {
- this.date.setMinutes(minutes);
- };
- goog.date.DateTime.prototype.setSeconds = function(seconds) {
- this.date.setSeconds(seconds);
- };
- goog.date.DateTime.prototype.setMilliseconds = function(ms) {
- this.date.setMilliseconds(ms);
- };
- goog.date.DateTime.prototype.setUTCHours = function(hours) {
- this.date.setUTCHours(hours);
- };
- goog.date.DateTime.prototype.setUTCMinutes = function(minutes) {
- this.date.setUTCMinutes(minutes);
- };
- goog.date.DateTime.prototype.setUTCSeconds = function(seconds) {
- this.date.setUTCSeconds(seconds);
- };
- goog.date.DateTime.prototype.setUTCMilliseconds = function(ms) {
- this.date.setUTCMilliseconds(ms);
- };
- goog.date.DateTime.prototype.isMidnight = function() {
- return this.getHours() == 0 && this.getMinutes() == 0 &&
- this.getSeconds() == 0 && this.getMilliseconds() == 0;
- };
- goog.date.DateTime.prototype.add = function(interval) {
- goog.date.Date.prototype.add.call(this, interval);
- if (interval.hours) {
- this.setUTCHours(this.date.getUTCHours() + interval.hours);
- }
- if (interval.minutes) {
- this.setUTCMinutes(this.date.getUTCMinutes() + interval.minutes);
- }
- if (interval.seconds) {
- this.setUTCSeconds(this.date.getUTCSeconds() + interval.seconds);
- }
- };
- goog.date.DateTime.prototype.toIsoString = function(opt_verbose, opt_tz) {
- var dateString = goog.date.Date.prototype.toIsoString.call(this, opt_verbose);
- if (opt_verbose) {
- return dateString + ' ' + goog.string.padNumber(this.getHours(), 2) + ':' +
- goog.string.padNumber(this.getMinutes(), 2) + ':' +
- goog.string.padNumber(this.getSeconds(), 2) +
- (opt_tz ? this.getTimezoneOffsetString() : '');
- }
- return dateString + 'T' + goog.string.padNumber(this.getHours(), 2) +
- goog.string.padNumber(this.getMinutes(), 2) +
- goog.string.padNumber(this.getSeconds(), 2) +
- (opt_tz ? this.getTimezoneOffsetString() : '');
- };
- goog.date.DateTime.prototype.toXmlDateTime = function(opt_timezone) {
- return goog.date.Date.prototype.toIsoString.call(this, true) + 'T' +
- goog.string.padNumber(this.getHours(), 2) + ':' +
- goog.string.padNumber(this.getMinutes(), 2) + ':' +
- goog.string.padNumber(this.getSeconds(), 2) +
- (opt_timezone ? this.getTimezoneOffsetString() : '');
- };
- goog.date.DateTime.prototype.toUTCIsoString = function(opt_verbose, opt_tz) {
- var dateStr = goog.date.Date.prototype.toUTCIsoString.call(this, opt_verbose);
- if (opt_verbose) {
- return dateStr + ' ' + goog.string.padNumber(this.getUTCHours(), 2) + ':' +
- goog.string.padNumber(this.getUTCMinutes(), 2) + ':' +
- goog.string.padNumber(this.getUTCSeconds(), 2) + (opt_tz ? 'Z' : '');
- }
- return dateStr + 'T' + goog.string.padNumber(this.getUTCHours(), 2) +
- goog.string.padNumber(this.getUTCMinutes(), 2) +
- goog.string.padNumber(this.getUTCSeconds(), 2) + (opt_tz ? 'Z' : '');
- };
- goog.date.DateTime.prototype.toUTCRfc3339String = function() {
- var date = this.toUTCIsoString(true).replace(' ', 'T');
- var millis = this.getUTCMilliseconds();
- return (millis ? date + '.' + millis : date) + 'Z';
- };
- goog.date.DateTime.prototype.equals = function(other) {
- return this.getTime() == other.getTime();
- };
- goog.date.DateTime.prototype.toString = function() {
- return this.toIsoString();
- };
- goog.date.DateTime.prototype.toUsTimeString = function(
- opt_padHours, opt_showAmPm, opt_omitZeroMinutes) {
- var hours = this.getHours();
-
- if (!goog.isDef(opt_showAmPm)) {
- opt_showAmPm = true;
- }
-
- var isPM = hours == 12;
-
- if (hours > 12) {
- hours -= 12;
- isPM = true;
- }
-
- if (hours == 0 && opt_showAmPm) {
- hours = 12;
- }
- var label = opt_padHours ? goog.string.padNumber(hours, 2) : String(hours);
- var minutes = this.getMinutes();
- if (!opt_omitZeroMinutes || minutes > 0) {
- label += ':' + goog.string.padNumber(minutes, 2);
- }
-
- if (opt_showAmPm) {
- label += isPM ? ' PM' : ' AM';
- }
- return label;
- };
- goog.date.DateTime.prototype.toIsoTimeString = function(opt_showSeconds) {
- var hours = this.getHours();
- var label = goog.string.padNumber(hours, 2) + ':' +
- goog.string.padNumber(this.getMinutes(), 2);
- if (!goog.isDef(opt_showSeconds) || opt_showSeconds) {
- label += ':' + goog.string.padNumber(this.getSeconds(), 2);
- }
- return label;
- };
- goog.date.DateTime.prototype.clone = function() {
- var date = new goog.date.DateTime(this.date);
- date.setFirstDayOfWeek(this.getFirstDayOfWeek());
- date.setFirstWeekCutOffDay(this.getFirstWeekCutOffDay());
- return date;
- };
|