@fr0st/datetime 5.0.0 → 5.1.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/README.md +37 -29
- package/dist/frost-datetime.js +2921 -0
- package/dist/frost-datetime.js.map +1 -0
- package/dist/frost-datetime.min.js +1 -0
- package/dist/frost-datetime.min.js.map +1 -0
- package/package.json +6 -6
- package/src/date-time.js +30 -44
- package/src/helpers.js +2 -2
- package/src/prototype/utility.js +34 -26
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ import DateTime from '@fr0st/datetime';
|
|
|
44
44
|
## Date Creation
|
|
45
45
|
|
|
46
46
|
- `dateString` is a string representing the date, and will default to the current timestamp.
|
|
47
|
-
- `options` is an object containing
|
|
47
|
+
- `options` is an object containing options for creating the new date.
|
|
48
48
|
- `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
|
|
49
49
|
- `locale` is a string representing the locale of the date, and will default to the system locale.
|
|
50
50
|
|
|
@@ -55,7 +55,7 @@ const dateTime = new DateTime(dateString, options);
|
|
|
55
55
|
**From Array**
|
|
56
56
|
|
|
57
57
|
- `dateArray` is an array containing the year, month, date, hours, minutes, seconds and milliseconds.
|
|
58
|
-
- `options` is an object containing
|
|
58
|
+
- `options` is an object containing options for creating the new date.
|
|
59
59
|
- `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
|
|
60
60
|
- `locale` is a string representing the locale of the date, and will default to the system locale.
|
|
61
61
|
|
|
@@ -68,7 +68,7 @@ The month and date in the `dateArray` will default to 1 if not set. The hours, m
|
|
|
68
68
|
**From Date**
|
|
69
69
|
|
|
70
70
|
- `dateObj` is a native JS *Date* object.
|
|
71
|
-
- `options` is an object containing
|
|
71
|
+
- `options` is an object containing options for creating the new date.
|
|
72
72
|
- `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
|
|
73
73
|
- `locale` is a string representing the locale of the date, and will default to the system locale.
|
|
74
74
|
|
|
@@ -82,7 +82,7 @@ If you wish to parse a date string and you know the exact format, you can use th
|
|
|
82
82
|
|
|
83
83
|
- `formatString` is a string containing the format you wish to use for parsing.
|
|
84
84
|
- `dateString` is a string representing the date you are parsing.
|
|
85
|
-
- `options` is an object containing
|
|
85
|
+
- `options` is an object containing options for creating the new date.
|
|
86
86
|
- `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
|
|
87
87
|
- `locale` is a string representing the locale of the date, and will default to the system locale.
|
|
88
88
|
|
|
@@ -97,7 +97,7 @@ const dateTime = DateTime.fromFormat(formatString, dateString, options);
|
|
|
97
97
|
**From ISO String**
|
|
98
98
|
|
|
99
99
|
- `dateString` is a string representing the date you are parsing.
|
|
100
|
-
- `options` is an object containing
|
|
100
|
+
- `options` is an object containing options for creating the new date.
|
|
101
101
|
- `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
|
|
102
102
|
- `locale` is a string representing the locale of the date, and will default to English.
|
|
103
103
|
|
|
@@ -114,7 +114,7 @@ const dateTime = DateTime.fromISOString(dateString, options);
|
|
|
114
114
|
**From Timestamp**
|
|
115
115
|
|
|
116
116
|
- `timestamp` is the number of seconds since the UNIX epoch.
|
|
117
|
-
- `options` is an object containing
|
|
117
|
+
- `options` is an object containing options for creating the new date.
|
|
118
118
|
- `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
|
|
119
119
|
- `locale` is a string representing the locale of the date, and will default to the system locale.
|
|
120
120
|
|
|
@@ -124,7 +124,7 @@ const dateTime = DateTime.fromTimestamp(timestamp, options);
|
|
|
124
124
|
|
|
125
125
|
**Now**
|
|
126
126
|
|
|
127
|
-
- `options` is an object containing
|
|
127
|
+
- `options` is an object containing options for creating the new date.
|
|
128
128
|
- `timeZone` is a string representing the time zone of the date, and will default to the system time zone.
|
|
129
129
|
- `locale` is a string representing the locale of the date, and will default to the system locale.
|
|
130
130
|
|
|
@@ -694,22 +694,23 @@ const daysInYear = dateTime.daysInYear();
|
|
|
694
694
|
Get the difference between two Dates.
|
|
695
695
|
|
|
696
696
|
- `other` is the *DateTime* object to compare to.
|
|
697
|
-
- `
|
|
698
|
-
- `
|
|
697
|
+
- `options` is an object containing options for how to compare the dates.
|
|
698
|
+
- `timeUnit` is a string representing the unit of time to return, and can be one of either "*year*", "*month*", "*week*", "*day*", "*hour*", "*minute*" or "*second*", or their pluralized versions.
|
|
699
|
+
- `relative` is a boolean indicating whether to return the relative difference, and will default to *true*.
|
|
699
700
|
|
|
700
701
|
If the `timeUnit` is omitted, this method will return the difference in milliseconds.
|
|
701
702
|
|
|
702
703
|
```javascript
|
|
703
|
-
const diff = dateTime.diff(other,
|
|
704
|
+
const diff = dateTime.diff(other, options);
|
|
704
705
|
```
|
|
705
706
|
|
|
706
707
|
If `relative` is *true* (default) the value returned will be the difference in the specified `timeUnit`, ignoring less significant values.
|
|
707
708
|
|
|
708
709
|
```javascript
|
|
709
|
-
DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').diff(DateTime.fromFormat('yyyy-MM-dd', '2018-12-31'), 'years', true); // 1
|
|
710
|
-
DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').diff(DateTime.fromFormat('yyyy-MM-dd', '2018-12-31'), 'years', false); // 0
|
|
711
|
-
DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').diff(DateTime.fromFormat('yyyy-MM-dd', '2017-12-31'), 'years', true); // 2
|
|
712
|
-
DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').diff(DateTime.fromFormat('yyyy-MM-dd', '2017-12-31'), 'years', false); // 1
|
|
710
|
+
DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').diff(DateTime.fromFormat('yyyy-MM-dd', '2018-12-31'), { timeUnit: 'years', relative: true }); // 1
|
|
711
|
+
DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').diff(DateTime.fromFormat('yyyy-MM-dd', '2018-12-31'), { timeUnit: 'years', relative: false }); // 0
|
|
712
|
+
DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').diff(DateTime.fromFormat('yyyy-MM-dd', '2017-12-31'), { timeUnit: 'years', relative: true }); // 2
|
|
713
|
+
DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').diff(DateTime.fromFormat('yyyy-MM-dd', '2017-12-31'), { timeUnit: 'years', relative: false }); // 1
|
|
713
714
|
```
|
|
714
715
|
|
|
715
716
|
**Era**
|
|
@@ -727,12 +728,13 @@ const era = dateTime.era(type);
|
|
|
727
728
|
Get the relative difference between two Dates in a human readable format using the current locale.
|
|
728
729
|
|
|
729
730
|
- `other` is the *DateTime* object to compare to.
|
|
730
|
-
- `
|
|
731
|
+
- `options` is an object containing options for how to compare the dates.
|
|
732
|
+
- `timeUnit` is a string representing the unit of time to return, and can be one of either "*year*", "*month*", "*week*", "*day*", "*hour*", "*minute*" or "*second*", or their pluralized versions.
|
|
731
733
|
|
|
732
734
|
If the `timeUnit` is omitted, this method will use the (relative) most significant non-zero value.
|
|
733
735
|
|
|
734
736
|
```javascript
|
|
735
|
-
const diff = dateTime.humanDiff(other,
|
|
737
|
+
const diff = dateTime.humanDiff(other, options);
|
|
736
738
|
```
|
|
737
739
|
|
|
738
740
|
The most significant non-zero value is determined where the unit of time has a non-relative difference, or the next relative difference value is greater than or equal to the unit of time.
|
|
@@ -751,10 +753,11 @@ DateTime.fromFormat('yyyy-MM-dd', '2019-01-01').humanDiff(DateTime.fromFormat('y
|
|
|
751
753
|
Return *true* if the *DateTime* is after another date.
|
|
752
754
|
|
|
753
755
|
- `other` is the *DateTime* object to compare to.
|
|
754
|
-
- `
|
|
756
|
+
- `options` is an object containing options for how to compare the dates.
|
|
757
|
+
- `granularity` is a string specifying the level of granularity to use when comparing the dates, and can be one of either "*year*", "*month*", "*day*", "*hour*", "*minute*" or "*second*".
|
|
755
758
|
|
|
756
759
|
```javascript
|
|
757
|
-
const isAfter = dateTime.isAfter(other,
|
|
760
|
+
const isAfter = dateTime.isAfter(other, options);
|
|
758
761
|
```
|
|
759
762
|
|
|
760
763
|
If a `granularity` is not specified, this method will compare the dates in milliseconds.
|
|
@@ -764,10 +767,11 @@ If a `granularity` is not specified, this method will compare the dates in milli
|
|
|
764
767
|
Return *true* if the *DateTime* is before another date.
|
|
765
768
|
|
|
766
769
|
- `other` is the *DateTime* object to compare to.
|
|
767
|
-
- `
|
|
770
|
+
- `options` is an object containing options for how to compare the dates.
|
|
771
|
+
- `granularity` is a string specifying the level of granularity to use when comparing the dates, and can be one of either "*year*", "*month*", "*day*", "*hour*", "*minute*" or "*second*".
|
|
768
772
|
|
|
769
773
|
```javascript
|
|
770
|
-
const isBefore = dateTime.isBefore(other,
|
|
774
|
+
const isBefore = dateTime.isBefore(other, options);
|
|
771
775
|
```
|
|
772
776
|
|
|
773
777
|
If a `granularity` is not specified, this method will compare the dates in milliseconds.
|
|
@@ -778,10 +782,11 @@ Return *true* if the *DateTime* is between two other dates.
|
|
|
778
782
|
|
|
779
783
|
- `start` is the starting *DateTime* object to compare to.
|
|
780
784
|
- `end` is the ending *DateTime* object to compare to.
|
|
781
|
-
- `
|
|
785
|
+
- `options` is an object containing options for how to compare the dates.
|
|
786
|
+
- `granularity` is a string specifying the level of granularity to use when comparing the dates, and can be one of either "*year*", "*month*", "*day*", "*hour*", "*minute*" or "*second*".
|
|
782
787
|
|
|
783
788
|
```javascript
|
|
784
|
-
const isBetween = dateTime.isBetween(start, end,
|
|
789
|
+
const isBetween = dateTime.isBetween(start, end, options);
|
|
785
790
|
```
|
|
786
791
|
|
|
787
792
|
If a `granularity` is not specified, this method will compare the dates in milliseconds.
|
|
@@ -807,10 +812,11 @@ const isLeapYear = dateTime.isLeapYear();
|
|
|
807
812
|
Return *true* if the *DateTime* is the same as another date.
|
|
808
813
|
|
|
809
814
|
- `other` is the *DateTime* object to compare to.
|
|
810
|
-
- `
|
|
815
|
+
- `options` is an object containing options for how to compare the dates.
|
|
816
|
+
- `granularity` is a string specifying the level of granularity to use when comparing the dates, and can be one of either "*year*", "*month*", "*day*", "*hour*", "*minute*" or "*second*".
|
|
811
817
|
|
|
812
818
|
```javascript
|
|
813
|
-
const isSame = dateTime.isSame(other,
|
|
819
|
+
const isSame = dateTime.isSame(other, options);
|
|
814
820
|
```
|
|
815
821
|
|
|
816
822
|
If a `granularity` is not specified, this method will compare the dates in milliseconds.
|
|
@@ -820,10 +826,11 @@ If a `granularity` is not specified, this method will compare the dates in milli
|
|
|
820
826
|
Return *true* if the *DateTime* is the same or after another date.
|
|
821
827
|
|
|
822
828
|
- `other` is the *DateTime* object to compare to.
|
|
823
|
-
- `
|
|
829
|
+
- `options` is an object containing options for how to compare the dates.
|
|
830
|
+
- `granularity` is a string specifying the level of granularity to use when comparing the dates, and can be one of either "*year*", "*month*", "*day*", "*hour*", "*minute*" or "*second*".
|
|
824
831
|
|
|
825
832
|
```javascript
|
|
826
|
-
const isSameOrAfter = dateTime.isSameOrAfter(other,
|
|
833
|
+
const isSameOrAfter = dateTime.isSameOrAfter(other, options);
|
|
827
834
|
```
|
|
828
835
|
|
|
829
836
|
If a `granularity` is not specified, this method will compare the dates in milliseconds.
|
|
@@ -833,10 +840,11 @@ If a `granularity` is not specified, this method will compare the dates in milli
|
|
|
833
840
|
Return *true* if the *DateTime* is the same or before another date.
|
|
834
841
|
|
|
835
842
|
- `other` is the *DateTime* object to compare to.
|
|
836
|
-
- `
|
|
843
|
+
- `options` is an object containing options for how to compare the dates.
|
|
844
|
+
- `granularity` is a string specifying the level of granularity to use when comparing the dates, and can be one of either "*year*", "*month*", "*day*", "*hour*", "*minute*" or "*second*".
|
|
837
845
|
|
|
838
846
|
```javascript
|
|
839
|
-
const isSameOrBefore = dateTime.isSameOrBefore(other,
|
|
847
|
+
const isSameOrBefore = dateTime.isSameOrBefore(other, options);
|
|
840
848
|
```
|
|
841
849
|
|
|
842
850
|
If a `granularity` is not specified, this method will compare the dates in milliseconds.
|
|
@@ -913,7 +921,7 @@ Get the default locale.
|
|
|
913
921
|
locale = DateTime.getDefaultLocale();
|
|
914
922
|
```
|
|
915
923
|
|
|
916
|
-
**
|
|
924
|
+
**Get Default Time Zone**
|
|
917
925
|
|
|
918
926
|
Get the default time zone.
|
|
919
927
|
|