datatables.net-datetime 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/datatables.net-datetime.1.3.0.nupkg +0 -0
- package/dist/dataTables.dateTime.js +124 -53
- package/dist/dataTables.dateTime.min.js +2 -2
- package/dist/dataTables.dateTime.min.mjs +2 -2
- package/dist/dataTables.dateTime.mjs +124 -52
- package/docs/api/valFormat().xml +52 -0
- package/examples/initialisation/luxon.xml +1 -1
- package/js/dataTables.dateTime.d.ts +2 -0
- package/js/dataTables.dateTime.js +124 -52
- package/nuget.nuspec +1 -1
- package/package.json +1 -1
- package/test/api/dateTime.val().js +1 -1
- package/test/api/dateTime.valFormat()-luxon.js +83 -0
- package/test/api/dateTime.valFormat().js +83 -0
- package/datatables.net-datetime.1.1.2.nupkg +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! DateTime picker for DataTables.net v1.
|
|
1
|
+
/*! DateTime picker for DataTables.net v1.3.0
|
|
2
2
|
*
|
|
3
3
|
* © SpryMedia Ltd, all rights reserved.
|
|
4
4
|
* License: MIT datatables.net/license/mit
|
|
@@ -10,7 +10,7 @@ import $ from 'jquery';
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @summary DateTime picker for DataTables.net
|
|
13
|
-
* @version 1.
|
|
13
|
+
* @version 1.3.0
|
|
14
14
|
* @file dataTables.dateTime.js
|
|
15
15
|
* @author SpryMedia Ltd
|
|
16
16
|
* @contact www.datatables.net/contact
|
|
@@ -68,25 +68,16 @@ var DateTime = function ( input, opts ) {
|
|
|
68
68
|
this.c.maxDate = new Date(this.c.maxDate);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
var timeBlock = function ( type ) {
|
|
72
|
-
return '<div class="'+classPrefix+'-timeblock">'+
|
|
73
|
-
'</div>';
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
var gap = function () {
|
|
77
|
-
return '<span>:</span>';
|
|
78
|
-
};
|
|
79
|
-
|
|
80
71
|
// DOM structure
|
|
81
72
|
var structure = $(
|
|
82
73
|
'<div class="'+classPrefix+'">'+
|
|
83
74
|
'<div class="'+classPrefix+'-date">'+
|
|
84
75
|
'<div class="'+classPrefix+'-title">'+
|
|
85
76
|
'<div class="'+classPrefix+'-iconLeft">'+
|
|
86
|
-
'<button type="button"
|
|
77
|
+
'<button type="button"></button>'+
|
|
87
78
|
'</div>'+
|
|
88
79
|
'<div class="'+classPrefix+'-iconRight">'+
|
|
89
|
-
'<button type="button"
|
|
80
|
+
'<button type="button"></button>'+
|
|
90
81
|
'</div>'+
|
|
91
82
|
'<div class="'+classPrefix+'-label">'+
|
|
92
83
|
'<span></span>'+
|
|
@@ -98,8 +89,8 @@ var DateTime = function ( input, opts ) {
|
|
|
98
89
|
'</div>'+
|
|
99
90
|
'</div>'+
|
|
100
91
|
'<div class="'+classPrefix+'-buttons">'+
|
|
101
|
-
'<a class="'+classPrefix+'-clear"
|
|
102
|
-
'<a class="'+classPrefix+'-today"
|
|
92
|
+
'<a class="'+classPrefix+'-clear"></a>'+
|
|
93
|
+
'<a class="'+classPrefix+'-today"></a>'+
|
|
103
94
|
'</div>'+
|
|
104
95
|
'<div class="'+classPrefix+'-calendar"></div>'+
|
|
105
96
|
'</div>'+
|
|
@@ -119,9 +110,11 @@ var DateTime = function ( input, opts ) {
|
|
|
119
110
|
calendar: structure.find( '.'+classPrefix+'-calendar' ),
|
|
120
111
|
time: structure.find( '.'+classPrefix+'-time' ),
|
|
121
112
|
error: structure.find( '.'+classPrefix+'-error' ),
|
|
122
|
-
buttons:
|
|
113
|
+
buttons: structure.find( '.'+classPrefix+'-buttons' ),
|
|
123
114
|
clear: structure.find( '.'+classPrefix+'-clear' ),
|
|
124
115
|
today: structure.find( '.'+classPrefix+'-today' ),
|
|
116
|
+
previous: structure.find( '.'+classPrefix+'-iconLeft' ),
|
|
117
|
+
next: structure.find( '.'+classPrefix+'-iconRight' ),
|
|
125
118
|
input: $(input)
|
|
126
119
|
};
|
|
127
120
|
|
|
@@ -252,25 +245,7 @@ $.extend( DateTime.prototype, {
|
|
|
252
245
|
this.s.d = this._dateToUtc(new Date());
|
|
253
246
|
}
|
|
254
247
|
else if ( typeof set === 'string' ) {
|
|
255
|
-
|
|
256
|
-
if(dateLib && dateLib == window.luxon) {
|
|
257
|
-
var luxDT = dateLib.DateTime.fromFormat(set, this.c.format)
|
|
258
|
-
this.s.d = luxDT.isValid ? luxDT.toJSDate() : null;
|
|
259
|
-
}
|
|
260
|
-
else if ( dateLib ) {
|
|
261
|
-
// Use moment, dayjs or luxon if possible (even for ISO8601 strings, since it
|
|
262
|
-
// will correctly handle 0000-00-00 and the like)
|
|
263
|
-
var m = dateLib.utc( set, this.c.format, this.c.locale, this.c.strict );
|
|
264
|
-
this.s.d = m.isValid() ? m.toDate() : null;
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
// Else must be using ISO8601 without a date library (constructor would
|
|
268
|
-
// have thrown an error otherwise)
|
|
269
|
-
var match = set.match(/(\d{4})\-(\d{2})\-(\d{2})/ );
|
|
270
|
-
this.s.d = match ?
|
|
271
|
-
new Date( Date.UTC(match[1], match[2]-1, match[3]) ) :
|
|
272
|
-
null;
|
|
273
|
-
}
|
|
248
|
+
this.s.d = this._convert(set, this.c.format, null);
|
|
274
249
|
}
|
|
275
250
|
|
|
276
251
|
if ( write || write === undefined ) {
|
|
@@ -300,6 +275,25 @@ $.extend( DateTime.prototype, {
|
|
|
300
275
|
return this;
|
|
301
276
|
},
|
|
302
277
|
|
|
278
|
+
/**
|
|
279
|
+
* Similar to `val()` but uses a given date / time format
|
|
280
|
+
*
|
|
281
|
+
* @param format Format to get the data as (getter) or that is input (setter)
|
|
282
|
+
* @param val Value to write (if undefined, used as a getter)
|
|
283
|
+
* @returns
|
|
284
|
+
*/
|
|
285
|
+
valFormat: function (format, val) {
|
|
286
|
+
if (! val) {
|
|
287
|
+
return this._convert(this.val(), null, format);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Convert from the format given here to the instance's configured format
|
|
291
|
+
this.val(
|
|
292
|
+
this._convert(val, format, null)
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
return this;
|
|
296
|
+
},
|
|
303
297
|
|
|
304
298
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
305
299
|
* Constructor
|
|
@@ -631,11 +625,75 @@ $.extend( DateTime.prototype, {
|
|
|
631
625
|
_compareDates: function( a, b ) {
|
|
632
626
|
// Can't use toDateString as that converts to local time
|
|
633
627
|
// luxon uses different method names so need to be able to call them
|
|
634
|
-
return
|
|
635
|
-
? dateLib.DateTime.fromJSDate(a).toISODate() === dateLib.DateTime.fromJSDate(b).toISODate()
|
|
628
|
+
return this._isLuxon()
|
|
629
|
+
? dateLib.DateTime.fromJSDate(a).toUTC().toISODate() === dateLib.DateTime.fromJSDate(b).toUTC().toISODate()
|
|
636
630
|
: this._dateToUtcString(a) === this._dateToUtcString(b);
|
|
637
631
|
},
|
|
638
632
|
|
|
633
|
+
/**
|
|
634
|
+
* Convert from one format to another
|
|
635
|
+
*
|
|
636
|
+
* @param {string|Date} val Value
|
|
637
|
+
* @param {string|null} from Format to convert from. If null a `Date` must be given
|
|
638
|
+
* @param {string|null} to Format to convert to. If null a `Date` will be returned
|
|
639
|
+
* @returns {string|Date} Converted value
|
|
640
|
+
*/
|
|
641
|
+
_convert(val, from, to) {
|
|
642
|
+
if (! val) {
|
|
643
|
+
return val;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
if (! dateLib) {
|
|
647
|
+
// Note that in here from and to can either be null or YYYY-MM-DD
|
|
648
|
+
// They cannot be anything else
|
|
649
|
+
if ((! from && ! to) || (from && to)) {
|
|
650
|
+
// No conversion
|
|
651
|
+
return val;
|
|
652
|
+
}
|
|
653
|
+
else if (! from) {
|
|
654
|
+
// Date in, string back
|
|
655
|
+
return val.getUTCFullYear() +'-'+
|
|
656
|
+
this._pad(val.getUTCMonth() + 1) +'-'+
|
|
657
|
+
this._pad(val.getUTCDate());
|
|
658
|
+
}
|
|
659
|
+
else { // (! to)
|
|
660
|
+
// String in, date back
|
|
661
|
+
var match = val.match(/(\d{4})\-(\d{2})\-(\d{2})/ );
|
|
662
|
+
return match ?
|
|
663
|
+
new Date( Date.UTC(match[1], match[2]-1, match[3]) ) :
|
|
664
|
+
null;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
else if (this._isLuxon()) {
|
|
668
|
+
// Luxon
|
|
669
|
+
var dtLux = val instanceof Date
|
|
670
|
+
? dateLib.DateTime.fromJSDate(val).toUTC()
|
|
671
|
+
: dateLib.DateTime.fromFormat(val, from);
|
|
672
|
+
|
|
673
|
+
if (! dtLux.isValid) {
|
|
674
|
+
return null;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
return to
|
|
678
|
+
? dtLux.toFormat(to)
|
|
679
|
+
: this._dateToUtc(dtLux.toJSDate());
|
|
680
|
+
}
|
|
681
|
+
else {
|
|
682
|
+
// Moment / DayJS
|
|
683
|
+
var dtMo = val instanceof Date
|
|
684
|
+
? dateLib.utc( val, undefined, this.c.locale, this.c.strict )
|
|
685
|
+
: dateLib.utc( val, from, this.c.locale, this.c.strict );
|
|
686
|
+
|
|
687
|
+
if (! dtMo.isValid()) {
|
|
688
|
+
return null;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
return to
|
|
692
|
+
? dtMo.format(to)
|
|
693
|
+
: dtMo.toDate();
|
|
694
|
+
}
|
|
695
|
+
},
|
|
696
|
+
|
|
639
697
|
/**
|
|
640
698
|
* When changing month, take account of the fact that some months don't have
|
|
641
699
|
* the same number of days. For example going from January to February you
|
|
@@ -697,8 +755,8 @@ $.extend( DateTime.prototype, {
|
|
|
697
755
|
*/
|
|
698
756
|
_dateToUtcString: function ( d ) {
|
|
699
757
|
// luxon uses different method names so need to be able to call them
|
|
700
|
-
return
|
|
701
|
-
? dateLib.DateTime.fromJSDate(d).toISODate()
|
|
758
|
+
return this._isLuxon()
|
|
759
|
+
? dateLib.DateTime.fromJSDate(d).toUTC().toISODate()
|
|
702
760
|
: d.getUTCFullYear()+'-'+
|
|
703
761
|
this._pad(d.getUTCMonth()+1)+'-'+
|
|
704
762
|
this._pad(d.getUTCDate());
|
|
@@ -957,6 +1015,17 @@ $.extend( DateTime.prototype, {
|
|
|
957
1015
|
return '<td class="'+this.c.classPrefix+'-week">' + weekNum + '</td>';
|
|
958
1016
|
},
|
|
959
1017
|
|
|
1018
|
+
/**
|
|
1019
|
+
* Determine if Luxon is being used
|
|
1020
|
+
*
|
|
1021
|
+
* @returns Flag for Luxon
|
|
1022
|
+
*/
|
|
1023
|
+
_isLuxon: function () {
|
|
1024
|
+
return dateLib && dateLib.DateTime && dateLib.Duration && dateLib.Settings
|
|
1025
|
+
? true
|
|
1026
|
+
: false;
|
|
1027
|
+
},
|
|
1028
|
+
|
|
960
1029
|
/**
|
|
961
1030
|
* Check if the instance has a date object value - it might be null.
|
|
962
1031
|
* If is doesn't set one to now.
|
|
@@ -1175,6 +1244,18 @@ $.extend( DateTime.prototype, {
|
|
|
1175
1244
|
|
|
1176
1245
|
this._options( 'month', this._range( 0, 11 ), i18n.months );
|
|
1177
1246
|
this._options( 'year', this._range( i, j ) );
|
|
1247
|
+
|
|
1248
|
+
// Set the language strings in case any have changed
|
|
1249
|
+
this.dom.today.text(i18n.today).text(i18n.today);
|
|
1250
|
+
this.dom.clear.text(i18n.clear).text(i18n.clear);
|
|
1251
|
+
this.dom.previous
|
|
1252
|
+
.attr('title', i18n.previous)
|
|
1253
|
+
.children('button')
|
|
1254
|
+
.text(i18n.previous);
|
|
1255
|
+
this.dom.next
|
|
1256
|
+
.attr('title', i18n.next)
|
|
1257
|
+
.children('button')
|
|
1258
|
+
.text(i18n.next);
|
|
1178
1259
|
},
|
|
1179
1260
|
|
|
1180
1261
|
/**
|
|
@@ -1311,8 +1392,8 @@ $.extend( DateTime.prototype, {
|
|
|
1311
1392
|
|
|
1312
1393
|
// luxon uses different method names so need to be able to call them. This happens a few time later in this method too
|
|
1313
1394
|
var luxDT = null
|
|
1314
|
-
if (
|
|
1315
|
-
luxDT = dateLib.DateTime.fromJSDate(d);
|
|
1395
|
+
if (this._isLuxon()) {
|
|
1396
|
+
luxDT = dateLib.DateTime.fromJSDate(d).toUTC();
|
|
1316
1397
|
}
|
|
1317
1398
|
|
|
1318
1399
|
var hours = luxDT != null
|
|
@@ -1421,17 +1502,8 @@ $.extend( DateTime.prototype, {
|
|
|
1421
1502
|
var date = this.s.d;
|
|
1422
1503
|
var out = '';
|
|
1423
1504
|
|
|
1424
|
-
// Use moment, dayjs or luxon if possible - otherwise it must be ISO8601 (or the
|
|
1425
|
-
// constructor would have thrown an error)
|
|
1426
|
-
// luxon uses different method names so need to be able to call them.
|
|
1427
1505
|
if (date) {
|
|
1428
|
-
out =
|
|
1429
|
-
? dateLib.DateTime.fromJSDate(this.s.d).toFormat(this.c.format)
|
|
1430
|
-
: dateLib ?
|
|
1431
|
-
dateLib.utc( date, undefined, this.c.locale, this.c.strict ).format( this.c.format ) :
|
|
1432
|
-
date.getUTCFullYear() +'-'+
|
|
1433
|
-
this._pad(date.getUTCMonth() + 1) +'-'+
|
|
1434
|
-
this._pad(date.getUTCDate());
|
|
1506
|
+
out = this._convert(date, null, this.c.format);
|
|
1435
1507
|
}
|
|
1436
1508
|
|
|
1437
1509
|
this.dom.input
|
|
@@ -1528,7 +1600,7 @@ DateTime.defaults = {
|
|
|
1528
1600
|
yearRange: 25
|
|
1529
1601
|
};
|
|
1530
1602
|
|
|
1531
|
-
DateTime.version = '1.
|
|
1603
|
+
DateTime.version = '1.3.0';
|
|
1532
1604
|
|
|
1533
1605
|
// Global export - if no conflicts
|
|
1534
1606
|
if (! window.DateTime) {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?>
|
|
2
|
+
<dt-api library="DateTime">
|
|
3
|
+
<name>valFormat()</name>
|
|
4
|
+
<summary>Get / set a formatted value for the instance.</summary>
|
|
5
|
+
<since>1.3.0</since>
|
|
6
|
+
|
|
7
|
+
<type type="function">
|
|
8
|
+
<signature>valFormat(format)</signature>
|
|
9
|
+
<description>Get the value of the DateTime instance.</description>
|
|
10
|
+
<parameter type="string" name="format">
|
|
11
|
+
The format that you want the date/time value in.
|
|
12
|
+
</parameter>
|
|
13
|
+
<returns type="string">The formatted value.</returns>
|
|
14
|
+
</type>
|
|
15
|
+
<type type="function">
|
|
16
|
+
<signature>valFormat(format, set)</signature>
|
|
17
|
+
<description>Set the value of the DateTime instance.</description>
|
|
18
|
+
<parameter type="string" name="format">
|
|
19
|
+
The format that the date / time value string is currently in.
|
|
20
|
+
</parameter>
|
|
21
|
+
<parameter type="string" name="set">
|
|
22
|
+
The value to be set, in the format given by the first parameter.
|
|
23
|
+
</parameter>
|
|
24
|
+
<returns type="DateTime">Self for chaining.</returns>
|
|
25
|
+
</type>
|
|
26
|
+
|
|
27
|
+
<description>
|
|
28
|
+
This method can be used to get or set the value for the DateTime instance, in a specific format. For example, it can be used to set a value given in a format that is not ISO8601, or you could read back a value in some other format (i.e. a localised human readable format).
|
|
29
|
+
|
|
30
|
+
The formatting options available will depend upon the date / time library being used (e.g. Moment.js or Luxon).
|
|
31
|
+
</description>
|
|
32
|
+
|
|
33
|
+
<example title="Get a value from the input with a specific format"><![CDATA[
|
|
34
|
+
|
|
35
|
+
let el = document.getElementById('example');
|
|
36
|
+
let dt = new DateTime(el);
|
|
37
|
+
|
|
38
|
+
el.addEventListener('change', function () {
|
|
39
|
+
console.log('Selected value is: ', dt.valFormat('MM-DD-YYYY'));
|
|
40
|
+
} );
|
|
41
|
+
|
|
42
|
+
]]></example>
|
|
43
|
+
|
|
44
|
+
<example title="Set a value into the input from a formatted string"><![CDATA[
|
|
45
|
+
|
|
46
|
+
let dt = new DateTime(document.getElementById('example'));
|
|
47
|
+
|
|
48
|
+
dt.valFormat('MM-DD-YY', '03-02-23");
|
|
49
|
+
|
|
50
|
+
]]></example>
|
|
51
|
+
|
|
52
|
+
</dt-api>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! DateTime picker for DataTables.net v1.
|
|
1
|
+
/*! DateTime picker for DataTables.net v1.3.0
|
|
2
2
|
*
|
|
3
3
|
* © SpryMedia Ltd, all rights reserved.
|
|
4
4
|
* License: MIT datatables.net/license/mit
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @summary DateTime picker for DataTables.net
|
|
9
|
-
* @version 1.
|
|
9
|
+
* @version 1.3.0
|
|
10
10
|
* @file dataTables.dateTime.js
|
|
11
11
|
* @author SpryMedia Ltd
|
|
12
12
|
* @contact www.datatables.net/contact
|
|
@@ -64,25 +64,16 @@ var DateTime = function ( input, opts ) {
|
|
|
64
64
|
this.c.maxDate = new Date(this.c.maxDate);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
var timeBlock = function ( type ) {
|
|
68
|
-
return '<div class="'+classPrefix+'-timeblock">'+
|
|
69
|
-
'</div>';
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
var gap = function () {
|
|
73
|
-
return '<span>:</span>';
|
|
74
|
-
};
|
|
75
|
-
|
|
76
67
|
// DOM structure
|
|
77
68
|
var structure = $(
|
|
78
69
|
'<div class="'+classPrefix+'">'+
|
|
79
70
|
'<div class="'+classPrefix+'-date">'+
|
|
80
71
|
'<div class="'+classPrefix+'-title">'+
|
|
81
72
|
'<div class="'+classPrefix+'-iconLeft">'+
|
|
82
|
-
'<button type="button"
|
|
73
|
+
'<button type="button"></button>'+
|
|
83
74
|
'</div>'+
|
|
84
75
|
'<div class="'+classPrefix+'-iconRight">'+
|
|
85
|
-
'<button type="button"
|
|
76
|
+
'<button type="button"></button>'+
|
|
86
77
|
'</div>'+
|
|
87
78
|
'<div class="'+classPrefix+'-label">'+
|
|
88
79
|
'<span></span>'+
|
|
@@ -94,8 +85,8 @@ var DateTime = function ( input, opts ) {
|
|
|
94
85
|
'</div>'+
|
|
95
86
|
'</div>'+
|
|
96
87
|
'<div class="'+classPrefix+'-buttons">'+
|
|
97
|
-
'<a class="'+classPrefix+'-clear"
|
|
98
|
-
'<a class="'+classPrefix+'-today"
|
|
88
|
+
'<a class="'+classPrefix+'-clear"></a>'+
|
|
89
|
+
'<a class="'+classPrefix+'-today"></a>'+
|
|
99
90
|
'</div>'+
|
|
100
91
|
'<div class="'+classPrefix+'-calendar"></div>'+
|
|
101
92
|
'</div>'+
|
|
@@ -115,9 +106,11 @@ var DateTime = function ( input, opts ) {
|
|
|
115
106
|
calendar: structure.find( '.'+classPrefix+'-calendar' ),
|
|
116
107
|
time: structure.find( '.'+classPrefix+'-time' ),
|
|
117
108
|
error: structure.find( '.'+classPrefix+'-error' ),
|
|
118
|
-
buttons:
|
|
109
|
+
buttons: structure.find( '.'+classPrefix+'-buttons' ),
|
|
119
110
|
clear: structure.find( '.'+classPrefix+'-clear' ),
|
|
120
111
|
today: structure.find( '.'+classPrefix+'-today' ),
|
|
112
|
+
previous: structure.find( '.'+classPrefix+'-iconLeft' ),
|
|
113
|
+
next: structure.find( '.'+classPrefix+'-iconRight' ),
|
|
121
114
|
input: $(input)
|
|
122
115
|
};
|
|
123
116
|
|
|
@@ -248,25 +241,7 @@ $.extend( DateTime.prototype, {
|
|
|
248
241
|
this.s.d = this._dateToUtc(new Date());
|
|
249
242
|
}
|
|
250
243
|
else if ( typeof set === 'string' ) {
|
|
251
|
-
|
|
252
|
-
if(dateLib && dateLib == window.luxon) {
|
|
253
|
-
var luxDT = dateLib.DateTime.fromFormat(set, this.c.format)
|
|
254
|
-
this.s.d = luxDT.isValid ? luxDT.toJSDate() : null;
|
|
255
|
-
}
|
|
256
|
-
else if ( dateLib ) {
|
|
257
|
-
// Use moment, dayjs or luxon if possible (even for ISO8601 strings, since it
|
|
258
|
-
// will correctly handle 0000-00-00 and the like)
|
|
259
|
-
var m = dateLib.utc( set, this.c.format, this.c.locale, this.c.strict );
|
|
260
|
-
this.s.d = m.isValid() ? m.toDate() : null;
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
// Else must be using ISO8601 without a date library (constructor would
|
|
264
|
-
// have thrown an error otherwise)
|
|
265
|
-
var match = set.match(/(\d{4})\-(\d{2})\-(\d{2})/ );
|
|
266
|
-
this.s.d = match ?
|
|
267
|
-
new Date( Date.UTC(match[1], match[2]-1, match[3]) ) :
|
|
268
|
-
null;
|
|
269
|
-
}
|
|
244
|
+
this.s.d = this._convert(set, this.c.format, null);
|
|
270
245
|
}
|
|
271
246
|
|
|
272
247
|
if ( write || write === undefined ) {
|
|
@@ -296,6 +271,25 @@ $.extend( DateTime.prototype, {
|
|
|
296
271
|
return this;
|
|
297
272
|
},
|
|
298
273
|
|
|
274
|
+
/**
|
|
275
|
+
* Similar to `val()` but uses a given date / time format
|
|
276
|
+
*
|
|
277
|
+
* @param format Format to get the data as (getter) or that is input (setter)
|
|
278
|
+
* @param val Value to write (if undefined, used as a getter)
|
|
279
|
+
* @returns
|
|
280
|
+
*/
|
|
281
|
+
valFormat: function (format, val) {
|
|
282
|
+
if (! val) {
|
|
283
|
+
return this._convert(this.val(), null, format);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Convert from the format given here to the instance's configured format
|
|
287
|
+
this.val(
|
|
288
|
+
this._convert(val, format, null)
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
return this;
|
|
292
|
+
},
|
|
299
293
|
|
|
300
294
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
301
295
|
* Constructor
|
|
@@ -627,11 +621,75 @@ $.extend( DateTime.prototype, {
|
|
|
627
621
|
_compareDates: function( a, b ) {
|
|
628
622
|
// Can't use toDateString as that converts to local time
|
|
629
623
|
// luxon uses different method names so need to be able to call them
|
|
630
|
-
return
|
|
631
|
-
? dateLib.DateTime.fromJSDate(a).toISODate() === dateLib.DateTime.fromJSDate(b).toISODate()
|
|
624
|
+
return this._isLuxon()
|
|
625
|
+
? dateLib.DateTime.fromJSDate(a).toUTC().toISODate() === dateLib.DateTime.fromJSDate(b).toUTC().toISODate()
|
|
632
626
|
: this._dateToUtcString(a) === this._dateToUtcString(b);
|
|
633
627
|
},
|
|
634
628
|
|
|
629
|
+
/**
|
|
630
|
+
* Convert from one format to another
|
|
631
|
+
*
|
|
632
|
+
* @param {string|Date} val Value
|
|
633
|
+
* @param {string|null} from Format to convert from. If null a `Date` must be given
|
|
634
|
+
* @param {string|null} to Format to convert to. If null a `Date` will be returned
|
|
635
|
+
* @returns {string|Date} Converted value
|
|
636
|
+
*/
|
|
637
|
+
_convert(val, from, to) {
|
|
638
|
+
if (! val) {
|
|
639
|
+
return val;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
if (! dateLib) {
|
|
643
|
+
// Note that in here from and to can either be null or YYYY-MM-DD
|
|
644
|
+
// They cannot be anything else
|
|
645
|
+
if ((! from && ! to) || (from && to)) {
|
|
646
|
+
// No conversion
|
|
647
|
+
return val;
|
|
648
|
+
}
|
|
649
|
+
else if (! from) {
|
|
650
|
+
// Date in, string back
|
|
651
|
+
return val.getUTCFullYear() +'-'+
|
|
652
|
+
this._pad(val.getUTCMonth() + 1) +'-'+
|
|
653
|
+
this._pad(val.getUTCDate());
|
|
654
|
+
}
|
|
655
|
+
else { // (! to)
|
|
656
|
+
// String in, date back
|
|
657
|
+
var match = val.match(/(\d{4})\-(\d{2})\-(\d{2})/ );
|
|
658
|
+
return match ?
|
|
659
|
+
new Date( Date.UTC(match[1], match[2]-1, match[3]) ) :
|
|
660
|
+
null;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
else if (this._isLuxon()) {
|
|
664
|
+
// Luxon
|
|
665
|
+
var dtLux = val instanceof Date
|
|
666
|
+
? dateLib.DateTime.fromJSDate(val).toUTC()
|
|
667
|
+
: dateLib.DateTime.fromFormat(val, from);
|
|
668
|
+
|
|
669
|
+
if (! dtLux.isValid) {
|
|
670
|
+
return null;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
return to
|
|
674
|
+
? dtLux.toFormat(to)
|
|
675
|
+
: this._dateToUtc(dtLux.toJSDate());
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
// Moment / DayJS
|
|
679
|
+
var dtMo = val instanceof Date
|
|
680
|
+
? dateLib.utc( val, undefined, this.c.locale, this.c.strict )
|
|
681
|
+
: dateLib.utc( val, from, this.c.locale, this.c.strict );
|
|
682
|
+
|
|
683
|
+
if (! dtMo.isValid()) {
|
|
684
|
+
return null;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
return to
|
|
688
|
+
? dtMo.format(to)
|
|
689
|
+
: dtMo.toDate();
|
|
690
|
+
}
|
|
691
|
+
},
|
|
692
|
+
|
|
635
693
|
/**
|
|
636
694
|
* When changing month, take account of the fact that some months don't have
|
|
637
695
|
* the same number of days. For example going from January to February you
|
|
@@ -693,8 +751,8 @@ $.extend( DateTime.prototype, {
|
|
|
693
751
|
*/
|
|
694
752
|
_dateToUtcString: function ( d ) {
|
|
695
753
|
// luxon uses different method names so need to be able to call them
|
|
696
|
-
return
|
|
697
|
-
? dateLib.DateTime.fromJSDate(d).toISODate()
|
|
754
|
+
return this._isLuxon()
|
|
755
|
+
? dateLib.DateTime.fromJSDate(d).toUTC().toISODate()
|
|
698
756
|
: d.getUTCFullYear()+'-'+
|
|
699
757
|
this._pad(d.getUTCMonth()+1)+'-'+
|
|
700
758
|
this._pad(d.getUTCDate());
|
|
@@ -953,6 +1011,17 @@ $.extend( DateTime.prototype, {
|
|
|
953
1011
|
return '<td class="'+this.c.classPrefix+'-week">' + weekNum + '</td>';
|
|
954
1012
|
},
|
|
955
1013
|
|
|
1014
|
+
/**
|
|
1015
|
+
* Determine if Luxon is being used
|
|
1016
|
+
*
|
|
1017
|
+
* @returns Flag for Luxon
|
|
1018
|
+
*/
|
|
1019
|
+
_isLuxon: function () {
|
|
1020
|
+
return dateLib && dateLib.DateTime && dateLib.Duration && dateLib.Settings
|
|
1021
|
+
? true
|
|
1022
|
+
: false;
|
|
1023
|
+
},
|
|
1024
|
+
|
|
956
1025
|
/**
|
|
957
1026
|
* Check if the instance has a date object value - it might be null.
|
|
958
1027
|
* If is doesn't set one to now.
|
|
@@ -1171,6 +1240,18 @@ $.extend( DateTime.prototype, {
|
|
|
1171
1240
|
|
|
1172
1241
|
this._options( 'month', this._range( 0, 11 ), i18n.months );
|
|
1173
1242
|
this._options( 'year', this._range( i, j ) );
|
|
1243
|
+
|
|
1244
|
+
// Set the language strings in case any have changed
|
|
1245
|
+
this.dom.today.text(i18n.today).text(i18n.today);
|
|
1246
|
+
this.dom.clear.text(i18n.clear).text(i18n.clear);
|
|
1247
|
+
this.dom.previous
|
|
1248
|
+
.attr('title', i18n.previous)
|
|
1249
|
+
.children('button')
|
|
1250
|
+
.text(i18n.previous);
|
|
1251
|
+
this.dom.next
|
|
1252
|
+
.attr('title', i18n.next)
|
|
1253
|
+
.children('button')
|
|
1254
|
+
.text(i18n.next);
|
|
1174
1255
|
},
|
|
1175
1256
|
|
|
1176
1257
|
/**
|
|
@@ -1307,8 +1388,8 @@ $.extend( DateTime.prototype, {
|
|
|
1307
1388
|
|
|
1308
1389
|
// luxon uses different method names so need to be able to call them. This happens a few time later in this method too
|
|
1309
1390
|
var luxDT = null
|
|
1310
|
-
if (
|
|
1311
|
-
luxDT = dateLib.DateTime.fromJSDate(d);
|
|
1391
|
+
if (this._isLuxon()) {
|
|
1392
|
+
luxDT = dateLib.DateTime.fromJSDate(d).toUTC();
|
|
1312
1393
|
}
|
|
1313
1394
|
|
|
1314
1395
|
var hours = luxDT != null
|
|
@@ -1417,17 +1498,8 @@ $.extend( DateTime.prototype, {
|
|
|
1417
1498
|
var date = this.s.d;
|
|
1418
1499
|
var out = '';
|
|
1419
1500
|
|
|
1420
|
-
// Use moment, dayjs or luxon if possible - otherwise it must be ISO8601 (or the
|
|
1421
|
-
// constructor would have thrown an error)
|
|
1422
|
-
// luxon uses different method names so need to be able to call them.
|
|
1423
1501
|
if (date) {
|
|
1424
|
-
out =
|
|
1425
|
-
? dateLib.DateTime.fromJSDate(this.s.d).toFormat(this.c.format)
|
|
1426
|
-
: dateLib ?
|
|
1427
|
-
dateLib.utc( date, undefined, this.c.locale, this.c.strict ).format( this.c.format ) :
|
|
1428
|
-
date.getUTCFullYear() +'-'+
|
|
1429
|
-
this._pad(date.getUTCMonth() + 1) +'-'+
|
|
1430
|
-
this._pad(date.getUTCDate());
|
|
1502
|
+
out = this._convert(date, null, this.c.format);
|
|
1431
1503
|
}
|
|
1432
1504
|
|
|
1433
1505
|
this.dom.input
|
|
@@ -1524,7 +1596,7 @@ DateTime.defaults = {
|
|
|
1524
1596
|
yearRange: 25
|
|
1525
1597
|
};
|
|
1526
1598
|
|
|
1527
|
-
DateTime.version = '1.
|
|
1599
|
+
DateTime.version = '1.3.0';
|
|
1528
1600
|
|
|
1529
1601
|
// Global export - if no conflicts
|
|
1530
1602
|
if (! window.DateTime) {
|
package/nuget.nuspec
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
|
3
3
|
<metadata>
|
|
4
4
|
<id>datatables.net-datetime</id>
|
|
5
|
-
<version>1.
|
|
5
|
+
<version>1.3.0</version>
|
|
6
6
|
<description>DataTables date / time picker</description>
|
|
7
7
|
<authors>SpryMedia Ltd</authors>
|
|
8
8
|
<projectUrl>http://datatables.net</projectUrl>
|
package/package.json
CHANGED
|
@@ -21,7 +21,7 @@ describe('dateTime - api - val()', function () {
|
|
|
21
21
|
dt.html('input');
|
|
22
22
|
it('Ensure its a function', function () {
|
|
23
23
|
el = new DateTime(document.getElementById('test'));
|
|
24
|
-
expect(typeof el.
|
|
24
|
+
expect(typeof el.val).toBe('function');
|
|
25
25
|
});
|
|
26
26
|
it('Getter returns null if no date set', function () {
|
|
27
27
|
expect(el.val()).toBe(null);
|