@8ms/helpers 2.0.20 → 2.0.22

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.
Binary file
package/README.md CHANGED
@@ -3,10 +3,8 @@ Use corepack to run Yarn 4 for this project.
3
3
 
4
4
  # Dates and Timezones
5
5
 
6
- Currently this is not possible to test using timezone-mock due to changing the timezone across the board and appears to not take effect.
6
+ Luxon used for Date Time managing.
7
7
 
8
- If a date is coming from the Database/Server it should be in UTC.
8
+ Always using UTC, this means no day light savings to worry about.
9
+ As Luxon DateTime instance can't be passed between server and client side, this needs to be reinitialized on client/server side.
9
10
 
10
- If a date is coming from the client side, the server needs to convert this input into UTC before being processed.
11
-
12
- Where possible dates should be passed as YYYYMMDD numbers so they are only converted for presentation purposes.
@@ -1,9 +1,5 @@
1
- import { DateTime, Zone } from "luxon";
1
+ import { DateTime } from "luxon";
2
2
  import { InputDate, Timeframe } from "./";
3
- /**
4
- * Convert an client's input (any time-zone) ready to be used by the server (UTC).
5
- */
6
- export declare const getUtcDate: (input?: InputDate, inputZone?: Zone) => DateTime<boolean>;
7
3
  export declare const getUnix: (input?: InputDate) => number;
8
4
  /**
9
5
  * Assume the input is always UTC.
@@ -1,29 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isLastWeek = exports.isThisWeek = exports.getYesterday = exports.getWeeksAgo = exports.getToday = exports.getTwoWeeksAgo = exports.getThisWeek = exports.getLastWeek = exports.getSunday = exports.getMonday = exports.getMin = exports.getMax = exports.getDatesBetween = exports.differenceInBusinessDays = exports.differenceInMinutes = exports.isWeekend = exports.isSunday = exports.isSaturday = exports.isFriday = exports.isThursday = exports.isWednesday = exports.isTuesday = exports.isMonday = exports.getDate = exports.getUnix = exports.getUtcDate = void 0;
3
+ exports.isLastWeek = exports.isThisWeek = exports.getYesterday = exports.getWeeksAgo = exports.getToday = exports.getTwoWeeksAgo = exports.getThisWeek = exports.getLastWeek = exports.getSunday = exports.getMonday = exports.getMin = exports.getMax = exports.getDatesBetween = exports.differenceInBusinessDays = exports.differenceInMinutes = exports.isWeekend = exports.isSunday = exports.isSaturday = exports.isFriday = exports.isThursday = exports.isWednesday = exports.isTuesday = exports.isMonday = exports.getDate = exports.getUnix = void 0;
4
4
  const luxon_1 = require("luxon");
5
- /**
6
- * Convert an client's input (any time-zone) ready to be used by the server (UTC).
7
- */
8
- const getUtcDate = (input, inputZone) => {
9
- let instance = luxon_1.DateTime.now();
10
- if (input) {
11
- if (input instanceof Date) {
12
- instance = luxon_1.DateTime.fromJSDate(input);
13
- }
14
- else if (input instanceof luxon_1.DateTime) {
15
- instance = input;
16
- }
17
- else {
18
- instance = luxon_1.DateTime.fromISO(input.toString(), { zone: inputZone });
19
- if (!instance.isValid) {
20
- instance = luxon_1.DateTime.fromFormat(input.toString(), "yyyy-MM-dd HH:mm:ss", { zone: inputZone });
21
- }
22
- }
23
- }
24
- return instance.toUTC();
25
- };
26
- exports.getUtcDate = getUtcDate;
27
5
  const getUnix = (input) => {
28
6
  return (0, exports.getDate)(input)
29
7
  .toUnixInteger();
@@ -35,11 +13,10 @@ exports.getUnix = getUnix;
35
13
  * If it's not UTC, it needs to be converted to UTC before being used.
36
14
  */
37
15
  const getDate = (input, setMidnight) => {
38
- let instance = luxon_1.DateTime.now();
16
+ let instance = luxon_1.DateTime.now().toUTC();
39
17
  if (input) {
40
18
  if (input instanceof Date) {
41
- instance = luxon_1.DateTime.fromJSDate(input)
42
- .toUTC();
19
+ instance = luxon_1.DateTime.fromJSDate(input, { zone: 'utc' });
43
20
  }
44
21
  else if (input instanceof luxon_1.DateTime) {
45
22
  instance = input.toUTC();
@@ -51,7 +28,8 @@ const getDate = (input, setMidnight) => {
51
28
  }
52
29
  }
53
30
  }
54
- // instance = instance.setZone("utc");
31
+ // Ensure the instance is in UTC timezone
32
+ instance = instance.setZone('utc', { keepLocalTime: false });
55
33
  if (setMidnight) {
56
34
  instance = instance.set({
57
35
  hour: 0,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "2.0.20",
4
+ "version": "2.0.22",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"