datatables.net-datetime 1.2.0 → 1.3.1
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/dist/dataTables.dateTime.js +135 -53
- package/dist/dataTables.dateTime.min.js +2 -2
- package/dist/dataTables.dateTime.min.mjs +2 -2
- package/dist/dataTables.dateTime.mjs +135 -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 +135 -52
- package/nuget.nuspec +1 -1
- package/package.json +1 -1
- package/test/api/dateTime.val().js +6 -6
- package/test/api/dateTime.valFormat()-luxon.js +83 -0
- package/test/api/dateTime.valFormat().js +83 -0
- package/test/options/dateTime.disableDays.js +1 -1
- package/test/options/dateTime.format.js +5 -9
- 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.1
|
|
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.1
|
|
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,9 @@ $.extend( DateTime.prototype, {
|
|
|
252
245
|
this.s.d = this._dateToUtc(new Date());
|
|
253
246
|
}
|
|
254
247
|
else if ( typeof set === 'string' ) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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._dateToUtc(
|
|
249
|
+
this._convert(set, this.c.format, null)
|
|
250
|
+
);
|
|
274
251
|
}
|
|
275
252
|
|
|
276
253
|
if ( write || write === undefined ) {
|
|
@@ -300,6 +277,25 @@ $.extend( DateTime.prototype, {
|
|
|
300
277
|
return this;
|
|
301
278
|
},
|
|
302
279
|
|
|
280
|
+
/**
|
|
281
|
+
* Similar to `val()` but uses a given date / time format
|
|
282
|
+
*
|
|
283
|
+
* @param format Format to get the data as (getter) or that is input (setter)
|
|
284
|
+
* @param val Value to write (if undefined, used as a getter)
|
|
285
|
+
* @returns
|
|
286
|
+
*/
|
|
287
|
+
valFormat: function (format, val) {
|
|
288
|
+
if (! val) {
|
|
289
|
+
return this._convert(this.val(), null, format);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Convert from the format given here to the instance's configured format
|
|
293
|
+
this.val(
|
|
294
|
+
this._convert(val, format, null)
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
return this;
|
|
298
|
+
},
|
|
303
299
|
|
|
304
300
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
305
301
|
* Constructor
|
|
@@ -631,11 +627,75 @@ $.extend( DateTime.prototype, {
|
|
|
631
627
|
_compareDates: function( a, b ) {
|
|
632
628
|
// Can't use toDateString as that converts to local time
|
|
633
629
|
// 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()
|
|
630
|
+
return this._isLuxon()
|
|
631
|
+
? dateLib.DateTime.fromJSDate(a).toUTC().toISODate() === dateLib.DateTime.fromJSDate(b).toUTC().toISODate()
|
|
636
632
|
: this._dateToUtcString(a) === this._dateToUtcString(b);
|
|
637
633
|
},
|
|
638
634
|
|
|
635
|
+
/**
|
|
636
|
+
* Convert from one format to another
|
|
637
|
+
*
|
|
638
|
+
* @param {string|Date} val Value
|
|
639
|
+
* @param {string|null} from Format to convert from. If null a `Date` must be given
|
|
640
|
+
* @param {string|null} to Format to convert to. If null a `Date` will be returned
|
|
641
|
+
* @returns {string|Date} Converted value
|
|
642
|
+
*/
|
|
643
|
+
_convert(val, from, to) {
|
|
644
|
+
if (! val) {
|
|
645
|
+
return val;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
if (! dateLib) {
|
|
649
|
+
// Note that in here from and to can either be null or YYYY-MM-DD
|
|
650
|
+
// They cannot be anything else
|
|
651
|
+
if ((! from && ! to) || (from && to)) {
|
|
652
|
+
// No conversion
|
|
653
|
+
return val;
|
|
654
|
+
}
|
|
655
|
+
else if (! from) {
|
|
656
|
+
// Date in, string back
|
|
657
|
+
return val.getUTCFullYear() +'-'+
|
|
658
|
+
this._pad(val.getUTCMonth() + 1) +'-'+
|
|
659
|
+
this._pad(val.getUTCDate());
|
|
660
|
+
}
|
|
661
|
+
else { // (! to)
|
|
662
|
+
// String in, date back
|
|
663
|
+
var match = val.match(/(\d{4})\-(\d{2})\-(\d{2})/ );
|
|
664
|
+
return match ?
|
|
665
|
+
new Date( match[1], match[2]-1, match[3] ) :
|
|
666
|
+
null;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
else if (this._isLuxon()) {
|
|
670
|
+
// Luxon
|
|
671
|
+
var dtLux = val instanceof Date
|
|
672
|
+
? dateLib.DateTime.fromJSDate(val).toUTC()
|
|
673
|
+
: dateLib.DateTime.fromFormat(val, from);
|
|
674
|
+
|
|
675
|
+
if (! dtLux.isValid) {
|
|
676
|
+
return null;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
return to
|
|
680
|
+
? dtLux.toFormat(to)
|
|
681
|
+
: dtLux.toJSDate();
|
|
682
|
+
}
|
|
683
|
+
else {
|
|
684
|
+
// Moment / DayJS
|
|
685
|
+
var dtMo = val instanceof Date
|
|
686
|
+
? dateLib.utc( val, undefined, this.c.locale, this.c.strict )
|
|
687
|
+
: dateLib( val, from, this.c.locale, this.c.strict );
|
|
688
|
+
|
|
689
|
+
if (! dtMo.isValid()) {
|
|
690
|
+
return null;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
return to
|
|
694
|
+
? dtMo.format(to)
|
|
695
|
+
: dtMo.toDate();
|
|
696
|
+
}
|
|
697
|
+
},
|
|
698
|
+
|
|
639
699
|
/**
|
|
640
700
|
* When changing month, take account of the fact that some months don't have
|
|
641
701
|
* the same number of days. For example going from January to February you
|
|
@@ -683,6 +743,10 @@ $.extend( DateTime.prototype, {
|
|
|
683
743
|
* @return {Date} Shifted date
|
|
684
744
|
*/
|
|
685
745
|
_dateToUtc: function ( s ) {
|
|
746
|
+
if (! s) {
|
|
747
|
+
return s;
|
|
748
|
+
}
|
|
749
|
+
|
|
686
750
|
return new Date( Date.UTC(
|
|
687
751
|
s.getFullYear(), s.getMonth(), s.getDate(),
|
|
688
752
|
s.getHours(), s.getMinutes(), s.getSeconds()
|
|
@@ -697,8 +761,8 @@ $.extend( DateTime.prototype, {
|
|
|
697
761
|
*/
|
|
698
762
|
_dateToUtcString: function ( d ) {
|
|
699
763
|
// luxon uses different method names so need to be able to call them
|
|
700
|
-
return
|
|
701
|
-
? dateLib.DateTime.fromJSDate(d).toISODate()
|
|
764
|
+
return this._isLuxon()
|
|
765
|
+
? dateLib.DateTime.fromJSDate(d).toUTC().toISODate()
|
|
702
766
|
: d.getUTCFullYear()+'-'+
|
|
703
767
|
this._pad(d.getUTCMonth()+1)+'-'+
|
|
704
768
|
this._pad(d.getUTCDate());
|
|
@@ -957,6 +1021,17 @@ $.extend( DateTime.prototype, {
|
|
|
957
1021
|
return '<td class="'+this.c.classPrefix+'-week">' + weekNum + '</td>';
|
|
958
1022
|
},
|
|
959
1023
|
|
|
1024
|
+
/**
|
|
1025
|
+
* Determine if Luxon is being used
|
|
1026
|
+
*
|
|
1027
|
+
* @returns Flag for Luxon
|
|
1028
|
+
*/
|
|
1029
|
+
_isLuxon: function () {
|
|
1030
|
+
return dateLib && dateLib.DateTime && dateLib.Duration && dateLib.Settings
|
|
1031
|
+
? true
|
|
1032
|
+
: false;
|
|
1033
|
+
},
|
|
1034
|
+
|
|
960
1035
|
/**
|
|
961
1036
|
* Check if the instance has a date object value - it might be null.
|
|
962
1037
|
* If is doesn't set one to now.
|
|
@@ -1175,6 +1250,18 @@ $.extend( DateTime.prototype, {
|
|
|
1175
1250
|
|
|
1176
1251
|
this._options( 'month', this._range( 0, 11 ), i18n.months );
|
|
1177
1252
|
this._options( 'year', this._range( i, j ) );
|
|
1253
|
+
|
|
1254
|
+
// Set the language strings in case any have changed
|
|
1255
|
+
this.dom.today.text(i18n.today).text(i18n.today);
|
|
1256
|
+
this.dom.clear.text(i18n.clear).text(i18n.clear);
|
|
1257
|
+
this.dom.previous
|
|
1258
|
+
.attr('title', i18n.previous)
|
|
1259
|
+
.children('button')
|
|
1260
|
+
.text(i18n.previous);
|
|
1261
|
+
this.dom.next
|
|
1262
|
+
.attr('title', i18n.next)
|
|
1263
|
+
.children('button')
|
|
1264
|
+
.text(i18n.next);
|
|
1178
1265
|
},
|
|
1179
1266
|
|
|
1180
1267
|
/**
|
|
@@ -1311,8 +1398,8 @@ $.extend( DateTime.prototype, {
|
|
|
1311
1398
|
|
|
1312
1399
|
// luxon uses different method names so need to be able to call them. This happens a few time later in this method too
|
|
1313
1400
|
var luxDT = null
|
|
1314
|
-
if (
|
|
1315
|
-
luxDT = dateLib.DateTime.fromJSDate(d);
|
|
1401
|
+
if (this._isLuxon()) {
|
|
1402
|
+
luxDT = dateLib.DateTime.fromJSDate(d).toUTC();
|
|
1316
1403
|
}
|
|
1317
1404
|
|
|
1318
1405
|
var hours = luxDT != null
|
|
@@ -1421,17 +1508,8 @@ $.extend( DateTime.prototype, {
|
|
|
1421
1508
|
var date = this.s.d;
|
|
1422
1509
|
var out = '';
|
|
1423
1510
|
|
|
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
1511
|
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());
|
|
1512
|
+
out = this._convert(date, null, this.c.format);
|
|
1435
1513
|
}
|
|
1436
1514
|
|
|
1437
1515
|
this.dom.input
|
|
@@ -1528,13 +1606,18 @@ DateTime.defaults = {
|
|
|
1528
1606
|
yearRange: 25
|
|
1529
1607
|
};
|
|
1530
1608
|
|
|
1531
|
-
DateTime.version = '1.
|
|
1609
|
+
DateTime.version = '1.3.1';
|
|
1532
1610
|
|
|
1533
1611
|
// Global export - if no conflicts
|
|
1534
1612
|
if (! window.DateTime) {
|
|
1535
1613
|
window.DateTime = DateTime;
|
|
1536
1614
|
}
|
|
1537
1615
|
|
|
1616
|
+
// Global DataTable
|
|
1617
|
+
if (window.DataTable) {
|
|
1618
|
+
window.DataTable.DateTime = DateTime;
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1538
1621
|
// Make available via jQuery
|
|
1539
1622
|
$.fn.dtDateTime = function (options) {
|
|
1540
1623
|
return this.each(function() {
|
|
@@ -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.1
|
|
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.1
|
|
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,9 @@ $.extend( DateTime.prototype, {
|
|
|
248
241
|
this.s.d = this._dateToUtc(new Date());
|
|
249
242
|
}
|
|
250
243
|
else if ( typeof set === 'string' ) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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._dateToUtc(
|
|
245
|
+
this._convert(set, this.c.format, null)
|
|
246
|
+
);
|
|
270
247
|
}
|
|
271
248
|
|
|
272
249
|
if ( write || write === undefined ) {
|
|
@@ -296,6 +273,25 @@ $.extend( DateTime.prototype, {
|
|
|
296
273
|
return this;
|
|
297
274
|
},
|
|
298
275
|
|
|
276
|
+
/**
|
|
277
|
+
* Similar to `val()` but uses a given date / time format
|
|
278
|
+
*
|
|
279
|
+
* @param format Format to get the data as (getter) or that is input (setter)
|
|
280
|
+
* @param val Value to write (if undefined, used as a getter)
|
|
281
|
+
* @returns
|
|
282
|
+
*/
|
|
283
|
+
valFormat: function (format, val) {
|
|
284
|
+
if (! val) {
|
|
285
|
+
return this._convert(this.val(), null, format);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Convert from the format given here to the instance's configured format
|
|
289
|
+
this.val(
|
|
290
|
+
this._convert(val, format, null)
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
return this;
|
|
294
|
+
},
|
|
299
295
|
|
|
300
296
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
301
297
|
* Constructor
|
|
@@ -627,11 +623,75 @@ $.extend( DateTime.prototype, {
|
|
|
627
623
|
_compareDates: function( a, b ) {
|
|
628
624
|
// Can't use toDateString as that converts to local time
|
|
629
625
|
// 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()
|
|
626
|
+
return this._isLuxon()
|
|
627
|
+
? dateLib.DateTime.fromJSDate(a).toUTC().toISODate() === dateLib.DateTime.fromJSDate(b).toUTC().toISODate()
|
|
632
628
|
: this._dateToUtcString(a) === this._dateToUtcString(b);
|
|
633
629
|
},
|
|
634
630
|
|
|
631
|
+
/**
|
|
632
|
+
* Convert from one format to another
|
|
633
|
+
*
|
|
634
|
+
* @param {string|Date} val Value
|
|
635
|
+
* @param {string|null} from Format to convert from. If null a `Date` must be given
|
|
636
|
+
* @param {string|null} to Format to convert to. If null a `Date` will be returned
|
|
637
|
+
* @returns {string|Date} Converted value
|
|
638
|
+
*/
|
|
639
|
+
_convert(val, from, to) {
|
|
640
|
+
if (! val) {
|
|
641
|
+
return val;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
if (! dateLib) {
|
|
645
|
+
// Note that in here from and to can either be null or YYYY-MM-DD
|
|
646
|
+
// They cannot be anything else
|
|
647
|
+
if ((! from && ! to) || (from && to)) {
|
|
648
|
+
// No conversion
|
|
649
|
+
return val;
|
|
650
|
+
}
|
|
651
|
+
else if (! from) {
|
|
652
|
+
// Date in, string back
|
|
653
|
+
return val.getUTCFullYear() +'-'+
|
|
654
|
+
this._pad(val.getUTCMonth() + 1) +'-'+
|
|
655
|
+
this._pad(val.getUTCDate());
|
|
656
|
+
}
|
|
657
|
+
else { // (! to)
|
|
658
|
+
// String in, date back
|
|
659
|
+
var match = val.match(/(\d{4})\-(\d{2})\-(\d{2})/ );
|
|
660
|
+
return match ?
|
|
661
|
+
new Date( match[1], match[2]-1, match[3] ) :
|
|
662
|
+
null;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
else if (this._isLuxon()) {
|
|
666
|
+
// Luxon
|
|
667
|
+
var dtLux = val instanceof Date
|
|
668
|
+
? dateLib.DateTime.fromJSDate(val).toUTC()
|
|
669
|
+
: dateLib.DateTime.fromFormat(val, from);
|
|
670
|
+
|
|
671
|
+
if (! dtLux.isValid) {
|
|
672
|
+
return null;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
return to
|
|
676
|
+
? dtLux.toFormat(to)
|
|
677
|
+
: dtLux.toJSDate();
|
|
678
|
+
}
|
|
679
|
+
else {
|
|
680
|
+
// Moment / DayJS
|
|
681
|
+
var dtMo = val instanceof Date
|
|
682
|
+
? dateLib.utc( val, undefined, this.c.locale, this.c.strict )
|
|
683
|
+
: dateLib( val, from, this.c.locale, this.c.strict );
|
|
684
|
+
|
|
685
|
+
if (! dtMo.isValid()) {
|
|
686
|
+
return null;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
return to
|
|
690
|
+
? dtMo.format(to)
|
|
691
|
+
: dtMo.toDate();
|
|
692
|
+
}
|
|
693
|
+
},
|
|
694
|
+
|
|
635
695
|
/**
|
|
636
696
|
* When changing month, take account of the fact that some months don't have
|
|
637
697
|
* the same number of days. For example going from January to February you
|
|
@@ -679,6 +739,10 @@ $.extend( DateTime.prototype, {
|
|
|
679
739
|
* @return {Date} Shifted date
|
|
680
740
|
*/
|
|
681
741
|
_dateToUtc: function ( s ) {
|
|
742
|
+
if (! s) {
|
|
743
|
+
return s;
|
|
744
|
+
}
|
|
745
|
+
|
|
682
746
|
return new Date( Date.UTC(
|
|
683
747
|
s.getFullYear(), s.getMonth(), s.getDate(),
|
|
684
748
|
s.getHours(), s.getMinutes(), s.getSeconds()
|
|
@@ -693,8 +757,8 @@ $.extend( DateTime.prototype, {
|
|
|
693
757
|
*/
|
|
694
758
|
_dateToUtcString: function ( d ) {
|
|
695
759
|
// luxon uses different method names so need to be able to call them
|
|
696
|
-
return
|
|
697
|
-
? dateLib.DateTime.fromJSDate(d).toISODate()
|
|
760
|
+
return this._isLuxon()
|
|
761
|
+
? dateLib.DateTime.fromJSDate(d).toUTC().toISODate()
|
|
698
762
|
: d.getUTCFullYear()+'-'+
|
|
699
763
|
this._pad(d.getUTCMonth()+1)+'-'+
|
|
700
764
|
this._pad(d.getUTCDate());
|
|
@@ -953,6 +1017,17 @@ $.extend( DateTime.prototype, {
|
|
|
953
1017
|
return '<td class="'+this.c.classPrefix+'-week">' + weekNum + '</td>';
|
|
954
1018
|
},
|
|
955
1019
|
|
|
1020
|
+
/**
|
|
1021
|
+
* Determine if Luxon is being used
|
|
1022
|
+
*
|
|
1023
|
+
* @returns Flag for Luxon
|
|
1024
|
+
*/
|
|
1025
|
+
_isLuxon: function () {
|
|
1026
|
+
return dateLib && dateLib.DateTime && dateLib.Duration && dateLib.Settings
|
|
1027
|
+
? true
|
|
1028
|
+
: false;
|
|
1029
|
+
},
|
|
1030
|
+
|
|
956
1031
|
/**
|
|
957
1032
|
* Check if the instance has a date object value - it might be null.
|
|
958
1033
|
* If is doesn't set one to now.
|
|
@@ -1171,6 +1246,18 @@ $.extend( DateTime.prototype, {
|
|
|
1171
1246
|
|
|
1172
1247
|
this._options( 'month', this._range( 0, 11 ), i18n.months );
|
|
1173
1248
|
this._options( 'year', this._range( i, j ) );
|
|
1249
|
+
|
|
1250
|
+
// Set the language strings in case any have changed
|
|
1251
|
+
this.dom.today.text(i18n.today).text(i18n.today);
|
|
1252
|
+
this.dom.clear.text(i18n.clear).text(i18n.clear);
|
|
1253
|
+
this.dom.previous
|
|
1254
|
+
.attr('title', i18n.previous)
|
|
1255
|
+
.children('button')
|
|
1256
|
+
.text(i18n.previous);
|
|
1257
|
+
this.dom.next
|
|
1258
|
+
.attr('title', i18n.next)
|
|
1259
|
+
.children('button')
|
|
1260
|
+
.text(i18n.next);
|
|
1174
1261
|
},
|
|
1175
1262
|
|
|
1176
1263
|
/**
|
|
@@ -1307,8 +1394,8 @@ $.extend( DateTime.prototype, {
|
|
|
1307
1394
|
|
|
1308
1395
|
// luxon uses different method names so need to be able to call them. This happens a few time later in this method too
|
|
1309
1396
|
var luxDT = null
|
|
1310
|
-
if (
|
|
1311
|
-
luxDT = dateLib.DateTime.fromJSDate(d);
|
|
1397
|
+
if (this._isLuxon()) {
|
|
1398
|
+
luxDT = dateLib.DateTime.fromJSDate(d).toUTC();
|
|
1312
1399
|
}
|
|
1313
1400
|
|
|
1314
1401
|
var hours = luxDT != null
|
|
@@ -1417,17 +1504,8 @@ $.extend( DateTime.prototype, {
|
|
|
1417
1504
|
var date = this.s.d;
|
|
1418
1505
|
var out = '';
|
|
1419
1506
|
|
|
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
1507
|
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());
|
|
1508
|
+
out = this._convert(date, null, this.c.format);
|
|
1431
1509
|
}
|
|
1432
1510
|
|
|
1433
1511
|
this.dom.input
|
|
@@ -1524,13 +1602,18 @@ DateTime.defaults = {
|
|
|
1524
1602
|
yearRange: 25
|
|
1525
1603
|
};
|
|
1526
1604
|
|
|
1527
|
-
DateTime.version = '1.
|
|
1605
|
+
DateTime.version = '1.3.1';
|
|
1528
1606
|
|
|
1529
1607
|
// Global export - if no conflicts
|
|
1530
1608
|
if (! window.DateTime) {
|
|
1531
1609
|
window.DateTime = DateTime;
|
|
1532
1610
|
}
|
|
1533
1611
|
|
|
1612
|
+
// Global DataTable
|
|
1613
|
+
if (window.DataTable) {
|
|
1614
|
+
window.DataTable.DateTime = DateTime;
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1534
1617
|
// Make available via jQuery
|
|
1535
1618
|
$.fn.dtDateTime = function (options) {
|
|
1536
1619
|
return this.each(function() {
|
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>
|