3 'remoto!stdlib:js/include/utils.js',
35 function date(year, month, day, hours, minutes, seconds, milliseconds)
39 if (arguments.length > 1)
40 _date =
new Date(year, month, day, hours, minutes, seconds, milliseconds);
41 else if (arguments.length == 1)
42 {
if (arguments[0] instanceof Date)
43 _date =
new Date(arguments[0]);
46 _date.setTime(arguments[0]);
53 _date.setMilliseconds(0);
71 date.wkdays = [
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat" ];
72 date.weekdays = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday" ];
73 date.months = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"June",
"July",
"Aug",
"Sept",
"Oct",
"Nov",
"Dec" ];
74 date.monthsFull = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December" ];
76 date.msMinute = 1000*60;
77 date.msHour = 1000*60*60;
78 date.msDay = 1000*60*60*24;
79 date.ms15 = 1000*60*15;
80 date.msWeek = 1000*60*60*24*7;
85 date.spad =
function(s,l)
89 s = s.substr(s.length-l,l);
102 firstDayOfWeek:
function()
104 var d =
new Date( this._date );
105 var day = d.getDay();
106 var diff = d.getDate() - day + (day == 0 ? -6:1);
111 d.setMilliseconds(0);
115 lastDayOfWeek:
function()
117 var d =
new Date( this._date );
118 var day = d.getDay();
119 var diff = d.getDate() - day + (day == 0 ? 0:7);
124 d.setMilliseconds(0);
128 fieldString:
function(sep)
134 _st +=
date.spad(d.getMonth()+1,2);
135 _st += sep +
date.spad(d.getDate(),2);
136 _st += sep + d.getFullYear();
140 timeString:
function(use12)
147 vv +=
date.spad(d.getHours()%12,2);
148 vv +=
":" +
date.spad(d.getMinutes(),2);
149 vv += d.getHours() > 11 ?
" pm" :
" am";
153 vv +=
date.spad(d.getHours(),2);
154 vv +=
":" +
date.spad(d.getMinutes(),2);
160 lengthString:
function()
163 var m = Math.round( t / (1000*60) );
164 var h = Math.floor( m / 60 );
165 return (h>0 ? h+
" hr"+(h>1?
"s":
"")+
", " :
"")+(m%60)+
" min"+((m%60)>1?
"s":
"");
168 lengthString2:
function()
171 var m = Math.round( t / (1000*60) );
172 var h = Math.floor( m / 60 );
173 return (h>0 ? h :
"")+
":"+
date.spad((m%60),2);
176 daysHoursMinutesString:
function()
179 var m = Math.floor( t / (1000*60) );
180 var h = Math.floor( m / 60 );
181 var d = Math.floor( h / 24 );
183 _s += d > 0 ? d +
":" :
"";
184 _s +=
date.spad( h % 24, 2 );
185 _s +=
":" +
date.spad( m % 60, 2 );
190 fullString:
function(withSeconds)
195 vv +=
date.spad(d.getMonth()+1,2);
196 vv +=
"/" +
date.spad(d.getDate(),2);
197 vv +=
"/" + d.getFullYear();
198 vv +=
" " +
date.spad(d.getHours(),2);
199 vv +=
":" +
date.spad(d.getMinutes(),2);
202 vv +=
":" +
date.spad(d.getSeconds(),2);
205 var zone = d.toLocaleTimeString(
'en-us',{timeZoneName:
'short'}).split(
' ')[2];
212 prettyString:
function()
215 var m = this._date.getMonth();
217 m =
date.months[ m ];
219 return m+
" "+this._date.getDate()+
", "+this._date.getFullYear();
222 dayMonthString:
function()
224 return (this._date.getMonth()+1)+
"/"+
date.spad(
this._date.getDate(),2);
242 return this._date.valueOf();
258 get year() {
return this._date.getFullYear();
261 get date() {
return this._date.getDate();
264 set date(d) {
return this._date.setDate(d);
267 get monthString() {
return date.months[ this._date.getMonth() ];
270 get monthStringFull() {
return date.monthsFull[ this._date.getMonth() ];
273 get month() {
return this._date.getMonth();
276 set month(m) {
return this._date.setMonth(m);
279 get daysInMonth() { var d =
new Date(this._date);
280 d.setMonth( this._date.getMonth()+1 );
282 return d.getDate()+1;
285 get day() {
return this._date.getDay();
288 get weekday() {
return date.wkdays[ this._date.getDay() ];
294 set minutes(m) { this._date.setHours(Math.floor(m/60));
295 this._date.setMinutes(m%60,0,0);
298 set seconds(s) { this._date.setSeconds(s);
301 get minutes() {
return this._date.getHours()*60+this._date.getMinutes();
304 get time() {
return this._date.getTime();
307 set time(t) {
return this._date.setTime(t);
312 headerString:
function()
314 var d = this._date.getDay();
315 var m = this._date.getMonth();
316 d =
date.weekdays[ d ];
317 m =
date.months[ m ];
319 return d+
", "+m+
" "+this._date.getDate();
322 daysTo:
function(end)
324 var t = this._date.valueOf();
325 var e = end._date.valueOf();
327 var days = Math.round(d/(1000*60*60*24));
331 minutesTo:
function(end)
333 var t = this._date.valueOf();
334 var e = end._date.valueOf();
336 var minutes = d/(1000*60);
351 isWeekend:
function()
353 var d = this._date.getDay();
355 return (d==0 || d==6);
360 var d =
new Date( this._date );
361 var diff = d.getDate() + 1;
366 d.setMilliseconds(0);
372 var d =
new Date( this._date );
373 var diff = d.getDate() - 1;
378 d.setMilliseconds(0);
384 var d =
new Date( this._date );
388 d.setMilliseconds(0);
392 offsetByDays:
function(off)
400 var d = this._date.getDate();
401 var h = this._date.getHours();
404 var t =
new Date(this._date);
413 return this.thisDay()._date.getTime();
418 return this.nextDay().startUTC() - 1;
421 intersects:
function(s,e,l)
423 var S = s._date.getTime() || Date.now();
424 var E = e._date.getTime() || Date.now();
425 var TS = this._date.getTime();
436 if (TS <= S && TE > S)
439 if (TS < E && TE > E)
442 if (TS >= S && TE <= E)
448 amountWithin:
function(s,n,l)
459 return this._date.getTime();
476 d.setMinutes(d.getMinutes()+1);
477 return d.getTime() - n.getTime();
The remoto date object, which has useful features not in the default javascript Date object.
getter id
returns the number of milliseconds since midnight January 1, 1970 UTC
timeToNextMinute
Calculate the time remaining until the next wallclock minute.
getter date
a getter DOCME
Utility functions for javascript clients.
bound(min, n, max)
Return a number where n is bounded by [min,max].