sugar-rails 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sugar/rails/version.rb +2 -2
- data/vendor/assets/javascripts/precompiled/development/array.js +50 -15
- data/vendor/assets/javascripts/precompiled/development/core.js +39 -13
- data/vendor/assets/javascripts/precompiled/development/date.js +137 -152
- data/vendor/assets/javascripts/precompiled/development/date_ranges.js +22 -10
- data/vendor/assets/javascripts/precompiled/development/es5.js +1 -1
- data/vendor/assets/javascripts/precompiled/development/function.js +7 -5
- data/vendor/assets/javascripts/precompiled/development/object.js +2 -2
- data/vendor/assets/javascripts/precompiled/minified/array.js +16 -16
- data/vendor/assets/javascripts/precompiled/minified/core.js +9 -8
- data/vendor/assets/javascripts/precompiled/minified/date.js +41 -39
- data/vendor/assets/javascripts/precompiled/minified/date_locales.js +9 -9
- data/vendor/assets/javascripts/precompiled/minified/date_ranges.js +3 -3
- data/vendor/assets/javascripts/precompiled/minified/es5.js +8 -7
- data/vendor/assets/javascripts/precompiled/minified/function.js +4 -4
- data/vendor/assets/javascripts/precompiled/minified/inflections.js +7 -7
- data/vendor/assets/javascripts/precompiled/minified/language.js +9 -9
- data/vendor/assets/javascripts/precompiled/minified/number.js +5 -5
- data/vendor/assets/javascripts/precompiled/minified/object.js +6 -6
- data/vendor/assets/javascripts/precompiled/minified/regexp.js +2 -2
- data/vendor/assets/javascripts/precompiled/minified/string.js +12 -12
- data/vendor/assets/javascripts/sugar-development.js +259 -199
- data/vendor/assets/javascripts/sugar-full.js +132 -128
- data/vendor/assets/javascripts/sugar.js +107 -103
- metadata +4 -4
@@ -26,19 +26,19 @@
|
|
26
26
|
{
|
27
27
|
token: 'f{1,4}|ms|milliseconds',
|
28
28
|
format: function(d) {
|
29
|
-
return d
|
29
|
+
return callDateGet(d, 'Milliseconds');
|
30
30
|
}
|
31
31
|
},
|
32
32
|
{
|
33
33
|
token: 'ss?|seconds',
|
34
34
|
format: function(d, len) {
|
35
|
-
return d
|
35
|
+
return callDateGet(d, 'Seconds');
|
36
36
|
}
|
37
37
|
},
|
38
38
|
{
|
39
39
|
token: 'mm?|minutes',
|
40
40
|
format: function(d, len) {
|
41
|
-
return d
|
41
|
+
return callDateGet(d, 'Minutes');
|
42
42
|
}
|
43
43
|
},
|
44
44
|
{
|
@@ -50,45 +50,48 @@
|
|
50
50
|
{
|
51
51
|
token: 'HH?|24hr',
|
52
52
|
format: function(d) {
|
53
|
-
return d
|
53
|
+
return callDateGet(d, 'Hours');
|
54
54
|
}
|
55
55
|
},
|
56
56
|
{
|
57
57
|
token: 'dd?|date|day',
|
58
58
|
format: function(d) {
|
59
|
-
return d
|
59
|
+
return callDateGet(d, 'Date');
|
60
60
|
}
|
61
61
|
},
|
62
62
|
{
|
63
63
|
token: 'dow|weekday',
|
64
64
|
word: true,
|
65
65
|
format: function(d, loc, n, t) {
|
66
|
-
|
66
|
+
var dow = callDateGet(d, 'Day');
|
67
|
+
return loc['weekdays'][dow + (n - 1) * 7];
|
67
68
|
}
|
68
69
|
},
|
69
70
|
{
|
70
71
|
token: 'MM?',
|
71
72
|
format: function(d) {
|
72
|
-
return d
|
73
|
+
return callDateGet(d, 'Month') + 1;
|
73
74
|
}
|
74
75
|
},
|
75
76
|
{
|
76
77
|
token: 'mon|month',
|
77
78
|
word: true,
|
78
79
|
format: function(d, loc, n, len) {
|
79
|
-
|
80
|
+
var month = callDateGet(d, 'Month');
|
81
|
+
return loc['months'][month + (n - 1) * 12];
|
80
82
|
}
|
81
83
|
},
|
82
84
|
{
|
83
85
|
token: 'y{2,4}|year',
|
84
86
|
format: function(d) {
|
85
|
-
return d
|
87
|
+
return callDateGet(d, 'FullYear');
|
86
88
|
}
|
87
89
|
},
|
88
90
|
{
|
89
91
|
token: '[Tt]{1,2}',
|
90
92
|
format: function(d, loc, n, format) {
|
91
|
-
var
|
93
|
+
var hours = callDateGet(d, 'Hours');
|
94
|
+
var str = loc['ampm'][floor(hours / 12)];
|
92
95
|
if(format.length === 1) str = str.slice(0,1);
|
93
96
|
if(format.slice(0,1) === 'T') str = str.toUpperCase();
|
94
97
|
return str;
|
@@ -116,8 +119,8 @@
|
|
116
119
|
{
|
117
120
|
token: 'ord',
|
118
121
|
format: function(d) {
|
119
|
-
var
|
120
|
-
return
|
122
|
+
var date = callDateGet(d, 'Date');
|
123
|
+
return date + getOrdinalizedSuffix(date);
|
121
124
|
}
|
122
125
|
}
|
123
126
|
];
|
@@ -126,6 +129,7 @@
|
|
126
129
|
{
|
127
130
|
unit: 'year',
|
128
131
|
method: 'FullYear',
|
132
|
+
ambiguous: true,
|
129
133
|
multiplier: function(d) {
|
130
134
|
var adjust = d ? (d.isLeapYear() ? 1 : 0) : 0.25;
|
131
135
|
return (365 + adjust) * 24 * 60 * 60 * 1000;
|
@@ -255,6 +259,10 @@
|
|
255
259
|
return code === 'en' || code === 'en-US' ? true : this['variant'];
|
256
260
|
},
|
257
261
|
|
262
|
+
matchAM: function(str) {
|
263
|
+
return str === this['ampm'][0];
|
264
|
+
},
|
265
|
+
|
258
266
|
matchPM: function(str) {
|
259
267
|
return str === this['ampm'][1];
|
260
268
|
},
|
@@ -349,7 +357,7 @@
|
|
349
357
|
}
|
350
358
|
|
351
359
|
function setLocalization(localeCode, set) {
|
352
|
-
var loc;
|
360
|
+
var loc, canAbbreviate;
|
353
361
|
|
354
362
|
function initializeField(name) {
|
355
363
|
var val = loc[name];
|
@@ -373,16 +381,15 @@
|
|
373
381
|
|
374
382
|
function setArray(name, abbreviate, multiple) {
|
375
383
|
var arr = [];
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
384
|
+
loc[name].forEach(function(full, i) {
|
385
|
+
if(abbreviate) {
|
386
|
+
full += '+' + full.slice(0,3);
|
387
|
+
}
|
388
|
+
eachAlternate(full, function(day, j) {
|
389
|
+
arr[j * multiple + i] = day.toLowerCase();
|
380
390
|
});
|
381
391
|
});
|
382
|
-
|
383
|
-
return str.slice(0,3).toLowerCase();
|
384
|
-
}));
|
385
|
-
return loc[name] = arr;
|
392
|
+
loc[name] = arr;
|
386
393
|
}
|
387
394
|
|
388
395
|
function getDigit(start, stop, allowNumbers) {
|
@@ -418,8 +425,10 @@
|
|
418
425
|
initializeField('modifiers');
|
419
426
|
'months,weekdays,units,numbers,articles,optionals,timeMarker,ampm,timeSuffixes,dateParse,timeParse'.split(',').forEach(initializeField);
|
420
427
|
|
421
|
-
|
422
|
-
|
428
|
+
canAbbreviate = !loc['monthSuffix'];
|
429
|
+
|
430
|
+
setArray('months', canAbbreviate, 12);
|
431
|
+
setArray('weekdays', canAbbreviate, 7);
|
423
432
|
setArray('units', false, 8);
|
424
433
|
setArray('numbers', false, 10);
|
425
434
|
|
@@ -505,10 +514,12 @@
|
|
505
514
|
function getDateParamsFromString(str, num) {
|
506
515
|
var params = {};
|
507
516
|
match = str.match(/^(\d+)?\s?(\w+?)s?$/i);
|
508
|
-
if(
|
509
|
-
num
|
517
|
+
if(match) {
|
518
|
+
if(isUndefined(num)) {
|
519
|
+
num = parseInt(match[1]) || 1;
|
520
|
+
}
|
521
|
+
params[match[2].toLowerCase()] = num;
|
510
522
|
}
|
511
|
-
params[match[2].toLowerCase()] = num;
|
512
523
|
return params;
|
513
524
|
}
|
514
525
|
|
@@ -554,14 +565,17 @@
|
|
554
565
|
});
|
555
566
|
}
|
556
567
|
|
557
|
-
function getExtendedDate(f, localeCode, prefer) {
|
568
|
+
function getExtendedDate(f, localeCode, prefer, forceUTC) {
|
558
569
|
var d = new date(), relative = false, baseLocalization, loc, format, set, unit, weekday, num, tmp, after;
|
570
|
+
|
571
|
+
d.utc(forceUTC);
|
572
|
+
|
559
573
|
if(isDate(f)) {
|
560
574
|
d = f.clone();
|
561
575
|
} else if(isNumber(f)) {
|
562
576
|
d = new date(f);
|
563
577
|
} else if(isObject(f)) {
|
564
|
-
d
|
578
|
+
d.set(f, true);
|
565
579
|
set = f;
|
566
580
|
} else if(isString(f)) {
|
567
581
|
|
@@ -579,6 +593,11 @@
|
|
579
593
|
format = dif;
|
580
594
|
loc = format.locale;
|
581
595
|
set = getFormatMatch(match, format.to, loc);
|
596
|
+
|
597
|
+
if(set['utc']) {
|
598
|
+
d.utc();
|
599
|
+
}
|
600
|
+
|
582
601
|
loc.cachedFormat = format;
|
583
602
|
|
584
603
|
if(set.timestamp) {
|
@@ -627,7 +646,8 @@
|
|
627
646
|
// to be set after the actual set because it requires overriding the "prefer" argument which
|
628
647
|
// could unintentionally send the year into the future, past, etc.
|
629
648
|
after = function() {
|
630
|
-
|
649
|
+
var w = d.getWeekday();
|
650
|
+
d.setWeekday((7 * (set['num'] - 1)) + (w > weekday ? weekday + 7 : weekday));
|
631
651
|
}
|
632
652
|
set['day'] = 1;
|
633
653
|
} else {
|
@@ -642,11 +662,13 @@
|
|
642
662
|
// If the time is 1pm-11pm advance the time by 12 hours.
|
643
663
|
if(loc.matchPM(set['ampm']) && set['hour'] < 12) {
|
644
664
|
set['hour'] += 12;
|
665
|
+
} else if(loc.matchAM(set['ampm']) && set['hour'] === 12) {
|
666
|
+
set['hour'] = 0;
|
645
667
|
}
|
646
668
|
|
647
669
|
// Adjust for timezone offset
|
648
670
|
if('offset_hours' in set || 'offset_minutes' in set) {
|
649
|
-
|
671
|
+
d.utc();
|
650
672
|
set['offset_minutes'] = set['offset_minutes'] || 0;
|
651
673
|
set['offset_minutes'] += set['offset_hours'] * 60;
|
652
674
|
if(set['offset_sign'] === '-') {
|
@@ -715,12 +737,12 @@
|
|
715
737
|
} else if(relative) {
|
716
738
|
d.advance(set);
|
717
739
|
} else {
|
718
|
-
if(
|
740
|
+
if(d._utc) {
|
719
741
|
// UTC times can traverse into other days or even months,
|
720
742
|
// so preemtively reset the time here to prevent this.
|
721
743
|
d.reset();
|
722
744
|
}
|
723
|
-
updateDate(d, set, true,
|
745
|
+
updateDate(d, set, true, false, prefer);
|
724
746
|
}
|
725
747
|
|
726
748
|
// If there is an "edge" it needs to be set after the
|
@@ -752,17 +774,18 @@
|
|
752
774
|
|
753
775
|
// If the year is two digits, add the most appropriate century prefix.
|
754
776
|
function getYearFromAbbreviation(year) {
|
755
|
-
return round(new date()
|
777
|
+
return round(callDateGet(new date(), 'FullYear') / 100) * 100 - round(year / 100) * 100 + year;
|
756
778
|
}
|
757
779
|
|
758
|
-
function getShortHour(d
|
759
|
-
var hours =
|
780
|
+
function getShortHour(d) {
|
781
|
+
var hours = callDateGet(d, 'Hours');
|
760
782
|
return hours === 0 ? 12 : hours - (floor(hours / 13) * 12);
|
761
783
|
}
|
762
784
|
|
763
785
|
// weeksSince won't work here as the result needs to be floored, not rounded.
|
764
786
|
function getWeekNumber(date) {
|
765
|
-
|
787
|
+
date = date.clone();
|
788
|
+
var dow = callDateGet(date, 'Day') || 7;
|
766
789
|
date.addDays(4 - dow).reset();
|
767
790
|
return 1 + floor(date.daysSince(date.clone().beginningOfYear()) / 7);
|
768
791
|
}
|
@@ -823,8 +846,8 @@
|
|
823
846
|
|
824
847
|
// Date comparison helpers
|
825
848
|
|
826
|
-
function compareDate(d, find, buffer) {
|
827
|
-
var p = getExtendedDate(find), accuracy = 0, loBuffer = 0, hiBuffer = 0, override, capitalized;
|
849
|
+
function compareDate(d, find, buffer, forceUTC) {
|
850
|
+
var p = getExtendedDate(find, null, null, forceUTC), accuracy = 0, loBuffer = 0, hiBuffer = 0, override, capitalized;
|
828
851
|
if(buffer > 0) {
|
829
852
|
loBuffer = hiBuffer = buffer;
|
830
853
|
override = true;
|
@@ -853,12 +876,11 @@
|
|
853
876
|
var t = d.getTime();
|
854
877
|
var min = p.date.getTime();
|
855
878
|
var max = max || (min + accuracy);
|
856
|
-
// Offset any shift that may occur as a result of DST traversal.
|
857
879
|
return t >= (min - loBuffer) && t <= (max + hiBuffer);
|
858
880
|
}
|
859
881
|
|
860
|
-
function updateDate(d, params, reset,
|
861
|
-
var weekday;
|
882
|
+
function updateDate(d, params, reset, advance, prefer) {
|
883
|
+
var weekday, specificityIndex;
|
862
884
|
|
863
885
|
function getParam(key) {
|
864
886
|
return isDefined(params[key]) ? params[key] : params[key + 's'];
|
@@ -868,8 +890,9 @@
|
|
868
890
|
return isDefined(getParam(key));
|
869
891
|
}
|
870
892
|
|
871
|
-
function canDisambiguate(
|
872
|
-
|
893
|
+
function canDisambiguate() {
|
894
|
+
var now = new date;
|
895
|
+
return (prefer === -1 && d > now) || (prefer === 1 && d < now);
|
873
896
|
}
|
874
897
|
|
875
898
|
if(isNumber(params) && advance) {
|
@@ -893,10 +916,11 @@
|
|
893
916
|
var isDay = u.unit === 'day';
|
894
917
|
if(paramExists(u.unit) || (isDay && paramExists('weekday'))) {
|
895
918
|
params.specificity = u.unit;
|
919
|
+
specificityIndex = +i;
|
896
920
|
return false;
|
897
921
|
} else if(reset && u.unit !== 'week' && (!isDay || !paramExists('week'))) {
|
898
922
|
// Days are relative to months, not weeks, so don't reset if a week exists.
|
899
|
-
|
923
|
+
callDateSet(d, u.method, (isDay ? 1 : 0));
|
900
924
|
}
|
901
925
|
});
|
902
926
|
|
@@ -905,23 +929,12 @@
|
|
905
929
|
var unit = u.unit, method = u.method, higherUnit = DateUnits[i - 1], value;
|
906
930
|
value = getParam(unit)
|
907
931
|
if(isUndefined(value)) return;
|
908
|
-
if(canDisambiguate(u, higherUnit)) {
|
909
|
-
// Formats like "June" have an ambiguous year. If no preference is stated, this
|
910
|
-
// is fine as "June of this year", however in a future context, this would mean
|
911
|
-
// "the next June", which may be either this year or next year. If we have an
|
912
|
-
// ambiguity *and* a preference for resolving it, then advance or rewind the
|
913
|
-
// higher order as necessary. Note that weekdays are handled differently below.
|
914
|
-
var current = callDateMethod(new date, 'get', utc, u.method);
|
915
|
-
if(current >= value === (prefer === 1)) {
|
916
|
-
d[higherUnit.addMethod](prefer);
|
917
|
-
}
|
918
|
-
}
|
919
932
|
if(advance) {
|
920
933
|
if(unit === 'week') {
|
921
934
|
value = (params['day'] || 0) + (value * 7);
|
922
935
|
method = 'Date';
|
923
936
|
}
|
924
|
-
value = (value * advance) +
|
937
|
+
value = (value * advance) + callDateGet(d, method);
|
925
938
|
} else if(unit === 'month' && paramExists('day')) {
|
926
939
|
// When setting the month, there is a chance that we will traverse into a new month.
|
927
940
|
// This happens in DST shifts, for example June 1st DST jumping to January 1st
|
@@ -937,9 +950,9 @@
|
|
937
950
|
// TL;DR This method avoids the edges of a month IF not advancing and the date is going
|
938
951
|
// to be set anyway, while checkMonthTraversal resets the date to the last day if advancing.
|
939
952
|
//
|
940
|
-
d
|
953
|
+
callDateSet(d, 'Date', 15);
|
941
954
|
}
|
942
|
-
|
955
|
+
callDateSet(d, method, value);
|
943
956
|
if(advance && unit === 'month') {
|
944
957
|
checkMonthTraversal(d, value);
|
945
958
|
}
|
@@ -949,24 +962,27 @@
|
|
949
962
|
// to reflect the updated date so that resetting works properly.
|
950
963
|
if(!advance && !paramExists('day') && paramExists('weekday')) {
|
951
964
|
var weekday = getParam('weekday'), isAhead, futurePreferred;
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
}
|
963
|
-
callDateMethod(d, 'set', utc, 'Weekday', weekday)
|
965
|
+
d.setWeekday(weekday);
|
966
|
+
}
|
967
|
+
|
968
|
+
if(canDisambiguate()) {
|
969
|
+
iterateOverObject(DateUnitsReversed.slice(specificityIndex + 1), function(i,u) {
|
970
|
+
var ambiguous = u.ambiguous || (u.unit === 'week' && paramExists('weekday'));
|
971
|
+
if(ambiguous && !paramExists(u.unit)) {
|
972
|
+
d[u.addMethod](prefer);
|
973
|
+
return false;
|
974
|
+
}
|
975
|
+
});
|
964
976
|
}
|
965
977
|
return d;
|
966
978
|
}
|
967
979
|
|
968
|
-
function
|
969
|
-
return d[
|
980
|
+
function callDateGet(d, method) {
|
981
|
+
return d['get' + (d._utc ? 'UTC' : '') + method]();
|
982
|
+
}
|
983
|
+
|
984
|
+
function callDateSet(d, method, value) {
|
985
|
+
return d['set' + (d._utc ? 'UTC' : '') + method](value);
|
970
986
|
}
|
971
987
|
|
972
988
|
// The ISO format allows times strung together without a demarcating ":", so make sure
|
@@ -1001,20 +1017,22 @@
|
|
1001
1017
|
|
1002
1018
|
function checkMonthTraversal(date, targetMonth) {
|
1003
1019
|
if(targetMonth < 0) targetMonth += 12;
|
1004
|
-
if(targetMonth % 12 != date
|
1005
|
-
date
|
1020
|
+
if(targetMonth % 12 != callDateGet(date, 'Month')) {
|
1021
|
+
callDateSet(date, 'Date', 0);
|
1006
1022
|
}
|
1007
1023
|
}
|
1008
1024
|
|
1009
1025
|
function createDate(args, prefer) {
|
1010
|
-
var f;
|
1026
|
+
var f, localeCode, forceUTC;
|
1011
1027
|
if(isNumber(args[1])) {
|
1012
1028
|
// If the second argument is a number, then we have an enumerated constructor type as in "new Date(2003, 2, 12);"
|
1013
1029
|
f = collectDateArguments(args)[0];
|
1014
1030
|
} else {
|
1015
|
-
f
|
1031
|
+
f = args[0];
|
1032
|
+
localeCode = args[1];
|
1033
|
+
forceUTC = args[2];
|
1016
1034
|
}
|
1017
|
-
return getExtendedDate(f,
|
1035
|
+
return getExtendedDate(f, localeCode, prefer, forceUTC).date;
|
1018
1036
|
}
|
1019
1037
|
|
1020
1038
|
function buildDateUnits() {
|
@@ -1251,9 +1269,9 @@
|
|
1251
1269
|
methods['beginningOf' + caps] = function() {
|
1252
1270
|
var set = {};
|
1253
1271
|
switch(unit) {
|
1254
|
-
case 'year': set['year']
|
1255
|
-
case 'month': set['month'] = this
|
1256
|
-
case 'day': set['day']
|
1272
|
+
case 'year': set['year'] = callDateGet(this, 'FullYear'); break;
|
1273
|
+
case 'month': set['month'] = callDateGet(this, 'Month'); break;
|
1274
|
+
case 'day': set['day'] = callDateGet(this, 'Date'); break;
|
1257
1275
|
case 'week': set['weekday'] = 0; break;
|
1258
1276
|
}
|
1259
1277
|
return this.set(set, true);
|
@@ -1366,8 +1384,8 @@
|
|
1366
1384
|
var weekdays = English['weekdays'].slice(0,7);
|
1367
1385
|
var months = English['months'].slice(0,12);
|
1368
1386
|
extendSimilar(date, true, false, special.concat(weekdays).concat(months), function(methods, name) {
|
1369
|
-
methods['is'+ simpleCapitalize(name)] = function() {
|
1370
|
-
|
1387
|
+
methods['is'+ simpleCapitalize(name)] = function(utc) {
|
1388
|
+
return this.is(name, 0, utc);
|
1371
1389
|
};
|
1372
1390
|
});
|
1373
1391
|
}
|
@@ -1395,10 +1413,10 @@
|
|
1395
1413
|
date.extend({
|
1396
1414
|
|
1397
1415
|
/***
|
1398
|
-
* @method Date.create(<d>, [locale] = currentLocale)
|
1416
|
+
* @method Date.create(<d>, [locale] = currentLocale, [utc] = false)
|
1399
1417
|
* @returns Date
|
1400
1418
|
* @short Alternate Date constructor which understands many different text formats, a timestamp, or another date.
|
1401
|
-
* @extra If no argument is given, date is assumed to be now. %Date.create% additionally can accept enumerated parameters as with the standard date constructor. [locale] can be passed to specify the locale that the date is in. When unspecified, the current locale (default is English) is assumed. For more information, see @date_format.
|
1419
|
+
* @extra If no argument is given, date is assumed to be now. %Date.create% additionally can accept enumerated parameters as with the standard date constructor. [locale] can be passed to specify the locale that the date is in. When unspecified, the current locale (default is English) is assumed. [utc] indicates a utc-based date. For more information, see @date_format.
|
1402
1420
|
* @example
|
1403
1421
|
*
|
1404
1422
|
* Date.create('July') -> July of this year
|
@@ -1417,7 +1435,7 @@
|
|
1417
1435
|
},
|
1418
1436
|
|
1419
1437
|
/***
|
1420
|
-
* @method Date.past(<d>, [locale] = currentLocale)
|
1438
|
+
* @method Date.past(<d>, [locale] = currentLocale, [utc] = false)
|
1421
1439
|
* @returns Date
|
1422
1440
|
* @short Alternate form of %Date.create% with any ambiguity assumed to be the past.
|
1423
1441
|
* @extra For example %"Sunday"% can be either "the Sunday coming up" or "the Sunday last" depending on context. Note that dates explicitly in the future ("next Sunday") will remain in the future. This method simply provides a hint when ambiguity exists.
|
@@ -1432,7 +1450,7 @@
|
|
1432
1450
|
},
|
1433
1451
|
|
1434
1452
|
/***
|
1435
|
-
* @method Date.future(<d>, [locale] = currentLocale)
|
1453
|
+
* @method Date.future(<d>, [locale] = currentLocale, [utc] = false)
|
1436
1454
|
* @returns Date
|
1437
1455
|
* @short Alternate form of %Date.create% with any ambiguity assumed to be the future.
|
1438
1456
|
* @extra For example %"Sunday"% can be either "the Sunday coming up" or "the Sunday last" depending on context. Note that dates explicitly in the past ("last Sunday") will remain in the past. This method simply provides a hint when ambiguity exists.
|
@@ -1505,10 +1523,7 @@
|
|
1505
1523
|
* @method set(<set>, [reset] = false)
|
1506
1524
|
* @returns Date
|
1507
1525
|
* @short Sets the date object.
|
1508
|
-
* @extra This method can accept multiple formats including a single number as a timestamp, an object, or enumerated parameters (as with the Date constructor). If [reset] is %true%, any units more specific than those passed will be reset.
|
1509
|
-
*
|
1510
|
-
* @set
|
1511
|
-
* setUTC
|
1526
|
+
* @extra This method can accept multiple formats including a single number as a timestamp, an object, or enumerated parameters (as with the Date constructor). If [reset] is %true%, any units more specific than those passed will be reset.
|
1512
1527
|
*
|
1513
1528
|
* @example
|
1514
1529
|
*
|
@@ -1523,19 +1538,10 @@
|
|
1523
1538
|
return updateDate(this, args[0], args[1])
|
1524
1539
|
},
|
1525
1540
|
|
1526
|
-
'setUTC': function() {
|
1527
|
-
var args = collectDateArguments(arguments);
|
1528
|
-
return updateDate(this, args[0], args[1], true)
|
1529
|
-
},
|
1530
|
-
|
1531
1541
|
/***
|
1532
1542
|
* @method setWeekday()
|
1533
1543
|
* @returns Nothing
|
1534
1544
|
* @short Sets the weekday of the date.
|
1535
|
-
* @extra %setUTCWeekday% sets according to universal time.
|
1536
|
-
*
|
1537
|
-
* @set
|
1538
|
-
* setUTCWeekday
|
1539
1545
|
*
|
1540
1546
|
* @example
|
1541
1547
|
*
|
@@ -1545,22 +1551,13 @@
|
|
1545
1551
|
***/
|
1546
1552
|
'setWeekday': function(dow) {
|
1547
1553
|
if(isUndefined(dow)) return;
|
1548
|
-
this
|
1549
|
-
},
|
1550
|
-
|
1551
|
-
'setUTCWeekday': function(dow) {
|
1552
|
-
if(isUndefined(dow)) return;
|
1553
|
-
this.setDate(this.getUTCDate() + dow - this.getDay());
|
1554
|
+
return callDateSet(this, 'Date', callDateGet(this, 'Date') + dow - callDateGet(this, 'Day'));
|
1554
1555
|
},
|
1555
1556
|
|
1556
1557
|
/***
|
1557
1558
|
* @method setWeek()
|
1558
1559
|
* @returns Nothing
|
1559
1560
|
* @short Sets the week (of the year).
|
1560
|
-
* @extra %setUTCWeek% sets according to universal time.
|
1561
|
-
*
|
1562
|
-
* @set
|
1563
|
-
* setUTCWeek
|
1564
1561
|
*
|
1565
1562
|
* @example
|
1566
1563
|
*
|
@@ -1569,41 +1566,27 @@
|
|
1569
1566
|
***/
|
1570
1567
|
'setWeek': function(week) {
|
1571
1568
|
if(isUndefined(week)) return;
|
1572
|
-
var date = this
|
1573
|
-
this
|
1574
|
-
this
|
1575
|
-
|
1576
|
-
|
1577
|
-
'setUTCWeek': function(week) {
|
1578
|
-
if(isUndefined(week)) return;
|
1579
|
-
var date = this.getUTCDate();
|
1580
|
-
this.setMonth(0);
|
1581
|
-
this.setUTCDate((week * 7) + 1);
|
1569
|
+
var date = callDateGet(this, 'Date');
|
1570
|
+
callDateSet(this, 'Month', 0);
|
1571
|
+
callDateSet(this, 'Date', (week * 7) + 1);
|
1572
|
+
return this.getTime();
|
1582
1573
|
},
|
1583
1574
|
|
1584
1575
|
/***
|
1585
1576
|
* @method getWeek()
|
1586
1577
|
* @returns Number
|
1587
1578
|
* @short Gets the date's week (of the year).
|
1588
|
-
* @extra %
|
1589
|
-
*
|
1590
|
-
* @set
|
1591
|
-
* getUTCWeek
|
1579
|
+
* @extra If %utc% is set on the date, the week will be according to UTC time.
|
1592
1580
|
*
|
1593
1581
|
* @example
|
1594
1582
|
*
|
1595
1583
|
* new Date().getWeek() -> today's week of the year
|
1596
|
-
* new Date().getUTCWeek() -> today's week of the year
|
1597
1584
|
*
|
1598
1585
|
***/
|
1599
1586
|
'getWeek': function() {
|
1600
1587
|
return getWeekNumber(this);
|
1601
1588
|
},
|
1602
1589
|
|
1603
|
-
'getUTCWeek': function() {
|
1604
|
-
return getWeekNumber(this.toUTC());
|
1605
|
-
},
|
1606
|
-
|
1607
1590
|
/***
|
1608
1591
|
* @method getUTCOffset([iso])
|
1609
1592
|
* @returns String
|
@@ -1615,27 +1598,26 @@
|
|
1615
1598
|
*
|
1616
1599
|
***/
|
1617
1600
|
'getUTCOffset': function(iso) {
|
1618
|
-
var offset = this.
|
1601
|
+
var offset = this._utc ? 0 : this.getTimezoneOffset();
|
1619
1602
|
var colon = iso === true ? ':' : '';
|
1620
1603
|
if(!offset && iso) return 'Z';
|
1621
1604
|
return padNumber(round(-offset / 60), 2, true) + colon + padNumber(offset % 60, 2);
|
1622
1605
|
},
|
1623
1606
|
|
1624
1607
|
/***
|
1625
|
-
* @method
|
1608
|
+
* @method utc([on] = true)
|
1626
1609
|
* @returns Date
|
1627
|
-
* @short
|
1628
|
-
* @extra
|
1610
|
+
* @short Sets the internal utc flag for the date. When on, UTC-based methods will be called internally.
|
1611
|
+
* @extra For more see @date_format.
|
1629
1612
|
* @example
|
1630
1613
|
*
|
1631
|
-
* new Date().
|
1614
|
+
* new Date().utc(true)
|
1615
|
+
* new Date().utc(false)
|
1632
1616
|
*
|
1633
1617
|
***/
|
1634
|
-
'
|
1635
|
-
|
1636
|
-
|
1637
|
-
d.utc = true;
|
1638
|
-
return d;
|
1618
|
+
'utc': function(set) {
|
1619
|
+
this._utc = set === true || arguments.length === 0;
|
1620
|
+
return this;
|
1639
1621
|
},
|
1640
1622
|
|
1641
1623
|
/***
|
@@ -1650,7 +1632,7 @@
|
|
1650
1632
|
*
|
1651
1633
|
***/
|
1652
1634
|
'isUTC': function() {
|
1653
|
-
return this.
|
1635
|
+
return !!this._utc || this.getTimezoneOffset() === 0;
|
1654
1636
|
},
|
1655
1637
|
|
1656
1638
|
/***
|
@@ -1668,7 +1650,7 @@
|
|
1668
1650
|
***/
|
1669
1651
|
'advance': function() {
|
1670
1652
|
var args = collectDateArguments(arguments, true);
|
1671
|
-
return updateDate(this, args[0], args[1],
|
1653
|
+
return updateDate(this, args[0], args[1], 1);
|
1672
1654
|
},
|
1673
1655
|
|
1674
1656
|
/***
|
@@ -1685,7 +1667,7 @@
|
|
1685
1667
|
***/
|
1686
1668
|
'rewind': function() {
|
1687
1669
|
var args = collectDateArguments(arguments, true);
|
1688
|
-
return updateDate(this, args[0], args[1],
|
1670
|
+
return updateDate(this, args[0], args[1], -1);
|
1689
1671
|
},
|
1690
1672
|
|
1691
1673
|
/***
|
@@ -1713,7 +1695,7 @@
|
|
1713
1695
|
* new Date().isAfter('yesterday') -> true
|
1714
1696
|
*
|
1715
1697
|
***/
|
1716
|
-
'isAfter': function(d, margin) {
|
1698
|
+
'isAfter': function(d, margin, utc) {
|
1717
1699
|
return this.getTime() > date.create(d).getTime() - (margin || 0);
|
1718
1700
|
},
|
1719
1701
|
|
@@ -1763,7 +1745,7 @@
|
|
1763
1745
|
*
|
1764
1746
|
***/
|
1765
1747
|
'isLeapYear': function() {
|
1766
|
-
var year = this
|
1748
|
+
var year = callDateGet(this, 'FullYear');
|
1767
1749
|
return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0);
|
1768
1750
|
},
|
1769
1751
|
|
@@ -1778,7 +1760,7 @@
|
|
1778
1760
|
*
|
1779
1761
|
***/
|
1780
1762
|
'daysInMonth': function() {
|
1781
|
-
return 32 - new date(this
|
1763
|
+
return 32 - callDateGet(new date(callDateGet(this, 'FullYear'), callDateGet(this, 'Month'), 32), 'Date');
|
1782
1764
|
},
|
1783
1765
|
|
1784
1766
|
/***
|
@@ -1848,21 +1830,22 @@
|
|
1848
1830
|
* Date.create().is(new Date(1776, 6, 4)) -> false
|
1849
1831
|
*
|
1850
1832
|
***/
|
1851
|
-
'is': function(d, margin) {
|
1852
|
-
var tmp;
|
1833
|
+
'is': function(d, margin, utc) {
|
1834
|
+
var tmp, comp;
|
1853
1835
|
if(!this.isValid()) return;
|
1854
1836
|
if(isString(d)) {
|
1855
1837
|
d = d.trim().toLowerCase();
|
1838
|
+
comp = this.clone().utc(utc);
|
1856
1839
|
switch(true) {
|
1857
1840
|
case d === 'future': return this.getTime() > new date().getTime();
|
1858
1841
|
case d === 'past': return this.getTime() < new date().getTime();
|
1859
|
-
case d === 'weekday': return
|
1860
|
-
case d === 'weekend': return
|
1861
|
-
case (tmp = English['weekdays'].indexOf(d) % 7) > -1: return
|
1862
|
-
case (tmp = English['months'].indexOf(d) % 12) > -1: return
|
1842
|
+
case d === 'weekday': return callDateGet(comp, 'Day') > 0 && callDateGet(comp, 'Day') < 6;
|
1843
|
+
case d === 'weekend': return callDateGet(comp, 'Day') === 0 || callDateGet(comp, 'Day') === 6;
|
1844
|
+
case (tmp = English['weekdays'].indexOf(d) % 7) > -1: return callDateGet(comp, 'Day') === tmp;
|
1845
|
+
case (tmp = English['months'].indexOf(d) % 12) > -1: return callDateGet(comp, 'Month') === tmp;
|
1863
1846
|
}
|
1864
1847
|
}
|
1865
|
-
return compareDate(this, d, margin);
|
1848
|
+
return compareDate(this, d, margin, utc);
|
1866
1849
|
},
|
1867
1850
|
|
1868
1851
|
/***
|
@@ -1896,7 +1879,9 @@
|
|
1896
1879
|
*
|
1897
1880
|
***/
|
1898
1881
|
'clone': function() {
|
1899
|
-
|
1882
|
+
var d = new date(this.getTime());
|
1883
|
+
d._utc = this._utc;
|
1884
|
+
return d;
|
1900
1885
|
}
|
1901
1886
|
|
1902
1887
|
});
|