@8ms/helpers 1.1.41 → 1.1.42

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.
@@ -7,7 +7,7 @@ export declare const timeZoneLondon = "Europe/London";
7
7
  * We can't use getDate here as it becomes a circular issue.
8
8
  * Returns a new Date instance.
9
9
  */
10
- declare const getTimeZoned: ({ input, setTimeZone }: GetTimeZonedType & {
10
+ declare const getTimeZoned: ({ input, setTimeZone, }: GetTimeZonedType & {
11
11
  input: Date;
12
12
  }) => Date;
13
13
  export default getTimeZoned;
@@ -16,7 +16,22 @@ var getTimeZoned = function (_a) {
16
16
  var input = _a.input, _b = _a.setTimeZone, setTimeZone = _b === void 0 ? exports.timeZoneLondon : _b;
17
17
  var dateInstance = input;
18
18
  if (setTimeZone) {
19
- dateInstance = new Date((0, date_fns_tz_1.formatInTimeZone)(dateInstance, setTimeZone, 'yyyy-MM-dd HH:mm:ss'));
19
+ // Cannot convert YYYY-MM-DD into new Date as Safari doesn't support this
20
+ var dateString = (0, date_fns_tz_1.formatInTimeZone)(dateInstance, setTimeZone, 'yyyy-MM-dd HH:mm:ss');
21
+ var year = Number(dateString.substring(0, 4));
22
+ var month = Number(dateString.substring(5, 7)) - 1;
23
+ var day = Number(dateString.substring(8, 10));
24
+ var hours = Number(dateString.substring(11, 13));
25
+ var minutes = Number(dateString.substring(14, 16));
26
+ var seconds = Number(dateString.substring(17, 19));
27
+ dateInstance = new Date();
28
+ // Reset the date to the 1st initially at 1am
29
+ dateInstance.setDate(1);
30
+ dateInstance.setHours(1, 0, 0, 0);
31
+ dateInstance.setFullYear(year);
32
+ dateInstance.setMonth(month);
33
+ dateInstance.setDate(day);
34
+ dateInstance.setHours(hours, minutes, seconds);
20
35
  // Fixes the timezone offset due to daylight savings
21
36
  dateInstance = (0, addMinutes_1.default)(dateInstance, dateInstance.getTimezoneOffset() * -1);
22
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
- "version": "1.1.41",
3
+ "version": "1.1.42",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"