@fr0st/datetime 5.0.2 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fr0st/datetime",
3
- "version": "5.0.2",
3
+ "version": "5.1.0",
4
4
  "description": "FrostDateTime is a free, open-source date manipulation library for JavaScript.",
5
5
  "keywords": [
6
6
  "date",
@@ -42,10 +42,10 @@
42
42
  "license": "MIT",
43
43
  "private": false,
44
44
  "devDependencies": {
45
- "eslint": "^8.31.0",
45
+ "eslint": "^8.41.0",
46
46
  "eslint-config-google": "^0.14.0",
47
47
  "mocha": "^10.2.0",
48
- "rollup": "^3.9.1",
49
- "terser": "^5.16.1"
48
+ "rollup": "^3.22.0",
49
+ "terser": "^5.17.4"
50
50
  }
51
51
  }
package/src/helpers.js CHANGED
@@ -41,12 +41,12 @@ export function compensateDiff(date, other, amount, compensate = true, compensat
41
41
  export function getBiggestDiff(date, other) {
42
42
  let lastResult;
43
43
  for (const timeUnit of ['year', 'month', 'week', 'day', 'hour', 'minute', 'second']) {
44
- const relativeDiff = date.diff(other, timeUnit);
44
+ const relativeDiff = date.diff(other, { timeUnit });
45
45
  if (lastResult && thresholds[timeUnit] && Math.abs(relativeDiff) >= thresholds[timeUnit]) {
46
46
  return lastResult;
47
47
  }
48
48
 
49
- const actualDiff = date.diff(other, timeUnit, false);
49
+ const actualDiff = date.diff(other, { timeUnit, relative: false });
50
50
  if (actualDiff) {
51
51
  return [relativeDiff, timeUnit];
52
52
  }
@@ -57,11 +57,12 @@ export function daysInYear() {
57
57
  /**
58
58
  * Get the difference between this and another Date.
59
59
  * @param {DateTime} [other] The date to compare to.
60
- * @param {string} [timeUnit] The unit of time.
61
- * @param {Boolean} [relative=true] Whether to use the relative difference.
60
+ * @param {object} [options] The options for comparing the dates.
61
+ * @param {string} [options.timeUnit] The unit of time.
62
+ * @param {Boolean} [options.relative=true] Whether to use the relative difference.
62
63
  * @return {number} The difference.
63
64
  */
64
- export function diff(other, timeUnit, relative = true) {
65
+ export function diff(other, { timeUnit, relative = true } = {}) {
65
66
  if (!other) {
66
67
  other = new this.constructor;
67
68
  }
@@ -201,10 +202,11 @@ export function era(type = 'long') {
201
202
  /**
202
203
  * Get the difference between this and another Date in human readable form.
203
204
  * @param {DateTime} [other] The date to compare to.
204
- * @param {string} [timeUnit] The unit of time.
205
+ * @param {object} [options] The options for comparing the dates.
206
+ * @param {string} [options.timeUnit] The unit of time.
205
207
  * @return {string} The difference in human readable form.
206
208
  */
207
- export function humanDiff(other, timeUnit) {
209
+ export function humanDiff(other, { timeUnit } = {}) {
208
210
  const relativeFormatter = getRelativeFormatter(this.getLocale());
209
211
 
210
212
  if (!relativeFormatter) {
@@ -217,7 +219,7 @@ export function humanDiff(other, timeUnit) {
217
219
 
218
220
  let amount;
219
221
  if (timeUnit) {
220
- amount = this.diff(other, timeUnit);
222
+ amount = this.diff(other, { timeUnit });
221
223
  } else {
222
224
  [amount, timeUnit] = getBiggestDiff(this, other);
223
225
  }
@@ -228,32 +230,35 @@ export function humanDiff(other, timeUnit) {
228
230
  /**
229
231
  * Determine whether this DateTime is after another date (optionally to a granularity).
230
232
  * @param {DateTime} [other] The date to compare to.
231
- * @param {string} [granularity] The level of granularity to use for comparison.
233
+ * @param {object} [options] The options for comparing the dates.
234
+ * @param {string} [options.granularity] The level of granularity to use for comparison.
232
235
  * @return {Boolean} TRUE if this DateTime is after the other date, otherwise FALSE.
233
236
  */
234
- export function isAfter(other, granularity) {
235
- return this.diff(other, granularity) > 0;
237
+ export function isAfter(other, { granularity } = {}) {
238
+ return this.diff(other, { timeUnit: granularity }) > 0;
236
239
  };
237
240
 
238
241
  /**
239
242
  * Determine whether this DateTime is before another date (optionally to a granularity).
240
243
  * @param {DateTime} [other] The date to compare to.
241
- * @param {string} [granularity] The level of granularity to use for comparison.
244
+ * @param {object} [options] The options for comparing the dates.
245
+ * @param {string} [options.granularity] The level of granularity to use for comparison.
242
246
  * @return {Boolean} TRUE if this DateTime is before the other date, otherwise FALSE.
243
247
  */
244
- export function isBefore(other, granularity) {
245
- return this.diff(other, granularity) < 0;
248
+ export function isBefore(other, { granularity } = {}) {
249
+ return this.diff(other, { timeUnit: granularity }) < 0;
246
250
  };
247
251
 
248
252
  /**
249
253
  * Determine whether this DateTime is between two other dates (optionally to a granularity).
250
254
  * @param {DateTime} [start] The first date to compare to.
251
255
  * @param {DateTime} [end] The second date to compare to.
252
- * @param {string} [granularity] The level of granularity to use for comparison.
256
+ * @param {object} [options] The options for comparing the dates.
257
+ * @param {string} [options.granularity] The level of granularity to use for comparison.
253
258
  * @return {Boolean} TRUE if this DateTime is between the other dates, otherwise FALSE.
254
259
  */
255
- export function isBetween(start, end, granularity) {
256
- return this.diff(start, granularity) > 0 && this.diff(end, granularity) < 0;
260
+ export function isBetween(start, end, { granularity } = {}) {
261
+ return this.diff(start, { timeUnit: granularity }) > 0 && this.diff(end, { timeUnit: granularity }) < 0;
257
262
  };
258
263
 
259
264
  /**
@@ -289,31 +294,34 @@ export function isLeapYear() {
289
294
  /**
290
295
  * Determine whether this DateTime is the same as another date (optionally to a granularity).
291
296
  * @param {DateTime} [other] The date to compare to.
292
- * @param {string} [granularity] The level of granularity to use for comparison.
297
+ * @param {object} [options] The options for comparing the dates.
298
+ * @param {string} [options.granularity] The level of granularity to use for comparison.
293
299
  * @return {Boolean} TRUE if this DateTime is the same as the other date, otherwise FALSE.
294
300
  */
295
- export function isSame(other, granularity) {
296
- return this.diff(other, granularity) === 0;
301
+ export function isSame(other, { granularity } = {}) {
302
+ return this.diff(other, { timeUnit: granularity }) === 0;
297
303
  };
298
304
 
299
305
  /**
300
306
  * Determine whether this DateTime is the same or after another date (optionally to a granularity).
301
307
  * @param {DateTime} [other] The date to compare to.
302
- * @param {string} [granularity] The level of granularity to use for comparison.
308
+ * @param {object} [options] The options for comparing the dates.
309
+ * @param {string} [options.granularity] The level of granularity to use for comparison.
303
310
  * @return {Boolean} TRUE if this DateTime is the same or after the other date, otherwise FALSE.
304
311
  */
305
- export function isSameOrAfter(other, granularity) {
306
- return this.diff(other, granularity) >= 0;
312
+ export function isSameOrAfter(other, { granularity } = {}) {
313
+ return this.diff(other, { timeUnit: granularity }) >= 0;
307
314
  };
308
315
 
309
316
  /**
310
317
  * Determine whether this DateTime is the same or before another date.
311
318
  * @param {DateTime} other The date to compare to.
312
- * @param {string} [granularity] The level of granularity to use for comparison.
319
+ * @param {object} [options] The options for comparing the dates.
320
+ * @param {string} [options.granularity] The level of granularity to use for comparison.
313
321
  * @return {Boolean} TRUE if this DateTime is the same or before the other date, otherwise FALSE.
314
322
  */
315
- export function isSameOrBefore(other, granularity) {
316
- return this.diff(other, granularity) <= 0;
323
+ export function isSameOrBefore(other, { granularity } = {}) {
324
+ return this.diff(other, { timeUnit: granularity }) <= 0;
317
325
  };
318
326
 
319
327
  /**