hematite 0.0.6 → 0.0.7
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.
- checksums.yaml +4 -4
- data/_config.yml +5 -0
- data/assets/js/DateUtil.mjs +41 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4b8f5537d27e5ffbcf75f2f7025cf8fb1aad2bb525e95fb6987e75e591313fa
|
4
|
+
data.tar.gz: 32705249f519772c0813700e2fe0b3e42bae9685df8a3b8e46c6fdaf8f9f800e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a80d098018413e4ed3aaa77f4ee81b381a36ac8388bb8b7939c4543ebb89f67db4fcc6eb498c9a3e19d593be8a5ad2a7dd3dddee35a0234f11734c2143883754
|
7
|
+
data.tar.gz: bd2c7f93936327e295a666056f26b83059c4af507242e6cb367d6bb312a2fe9d20714ee723ada04735b41f44f4cf76ee584b4c1c151477ef214552f2943e4fb4
|
data/_config.yml
CHANGED
@@ -27,6 +27,11 @@ hematite:
|
|
27
27
|
# The full year
|
28
28
|
year: numeric
|
29
29
|
|
30
|
+
parsing:
|
31
|
+
# True if the date should be parsed MM/DD/YYYY instead of
|
32
|
+
# DD/MM/YYYY
|
33
|
+
month_first: true
|
34
|
+
|
30
35
|
sidebar:
|
31
36
|
footer_html: 'This page was made with the Hematite Theme. <a href="https://github.com/personalizedrefrigerator/jekyll-hematite-theme">Contribute on GitHub</a>'
|
32
37
|
|
data/assets/js/DateUtil.mjs
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
---
|
2
2
|
---
|
3
3
|
|
4
|
+
import { assertEq } from "./assertions.mjs";
|
5
|
+
|
4
6
|
const MS_PER_DAY = 24 * 60 * 60 * 1000;
|
5
7
|
const MS_PER_WEEK = MS_PER_DAY * 7;
|
6
8
|
|
@@ -94,12 +96,39 @@ var DateUtil = {
|
|
94
96
|
|
95
97
|
/// Slightly more intelligent date parsing than new Date(string).
|
96
98
|
parse(text) {
|
99
|
+
text = text.trim();
|
100
|
+
|
97
101
|
// Remove -th, -rd, -ero suffexes
|
98
|
-
text = text.replaceAll(/(\d)(?:rd|th|ero)/g,
|
102
|
+
text = text.replaceAll(/(\d)(?:rd|st|th|ero)/g,
|
99
103
|
(fullMatch, group0) => group0);
|
100
|
-
|
104
|
+
let res = new Date(0);
|
105
|
+
|
106
|
+
let shortMatch = text.match(/^(\d+)\/(\d+)\/(\d{2,})$/);
|
107
|
+
|
108
|
+
// DD/MM/YY+ or MM/DD/YY+
|
109
|
+
if (shortMatch) {
|
110
|
+
let year = parseInt(shortMatch[3]);
|
111
|
+
{% if site.hematite.date_format.parsing.month_first %}
|
112
|
+
let month = parseInt(shortMatch[1]);
|
113
|
+
let day = parseInt(shortMatch[2]);
|
114
|
+
{% else %}
|
115
|
+
let month = parseInt(shortMatch[2]);
|
116
|
+
let day = parseInt(shortMatch[1]);
|
117
|
+
{% endif %}
|
118
|
+
|
119
|
+
if (shortMatch[3].length >= 4) {
|
120
|
+
res.setFullYear(year);
|
121
|
+
}
|
122
|
+
else if (shortMatch[3].length == 2){
|
123
|
+
res.setFullYear(2000 + year);
|
124
|
+
}
|
125
|
+
res.setMonth(month - 1, day);
|
126
|
+
}
|
127
|
+
else {
|
128
|
+
res = new Date(text);
|
129
|
+
}
|
101
130
|
|
102
|
-
return
|
131
|
+
return res;
|
103
132
|
},
|
104
133
|
|
105
134
|
/// Returns true iff the given object is a date object.
|
@@ -120,4 +149,13 @@ var DateUtil = {
|
|
120
149
|
},
|
121
150
|
};
|
122
151
|
|
152
|
+
assertEq("Check if new Date() is a date",
|
153
|
+
DateUtil.isDate(new Date()), true);
|
154
|
+
assertEq("Check if dates can be parsed",
|
155
|
+
DateUtil.parse("01/01/22").getFullYear(), 2022);
|
156
|
+
assertEq("Same day test 1",
|
157
|
+
DateUtil.datesAreOnSameDay(DateUtil.parse("01/02/22"), DateUtil.parse("01/02/2022")), true);
|
158
|
+
assertEq("Same day test 2",
|
159
|
+
DateUtil.datesAreOnSameDay(DateUtil.parse("01/01/22"), DateUtil.parse("January 1st, 2022")), true);
|
160
|
+
|
123
161
|
export default DateUtil;
|