@driveflux/time 6.0.3 → 6.0.4

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/dist/config.js CHANGED
@@ -1,14 +1,15 @@
1
1
  import { initSingleton } from '@driveflux/singleton';
2
- var getConfig = function getConfig() {
3
- return {
4
- timezone: typeof process !== 'undefined' ? process.env.TIME_ZONE || 'Asia/Kuala_Lumpur' : 'Asia/Kuala_Lumpur'
5
- };
6
- };
7
- export var config = initSingleton('timeConfig', getConfig);
8
- export var resetConfig = function resetConfig() {
2
+ const getConfig = () => ({
3
+ timezone: typeof process !== 'undefined'
4
+ ? process.env.TIME_ZONE || 'Asia/Kuala_Lumpur'
5
+ : 'Asia/Kuala_Lumpur',
6
+ });
7
+ export let config = initSingleton('timeConfig', getConfig);
8
+ export const resetConfig = () => {
9
9
  config = initSingleton('timeConfig', getConfig, true);
10
10
  return config;
11
11
  };
12
- export var setConfig = function setConfig(key, value) {
12
+ export const setConfig = (key, value) => {
13
13
  config[key] = value;
14
14
  };
15
+ //# sourceMappingURL=config.js.map
package/dist/index.js CHANGED
@@ -4,16 +4,17 @@ import { parse as fnsParse } from 'date-fns/parse';
4
4
  import { startOfDay } from 'date-fns/startOfDay';
5
5
  import * as dateFnsTz from 'date-fns-tz';
6
6
  import { config } from './config.js';
7
- var fromZonedTime = dateFnsTz.fromZonedTime, toZonedTime = dateFnsTz.toZonedTime;
7
+ const { fromZonedTime, toZonedTime } = dateFnsTz;
8
8
  /**
9
9
  * @see https://date-fns.org/docs/format
10
- */ export var DEFAULT_DATE_FORMAT = 'dd-MM-yyyy';
11
- export var DEFAULT_TIME_FORMAT = 'hh:mm a';
12
- export var NUMBERED_TIME_FORMAT = 'hh:mm';
13
- export var EASY_FORMATS = {
10
+ */
11
+ export const DEFAULT_DATE_FORMAT = 'dd-MM-yyyy';
12
+ export const DEFAULT_TIME_FORMAT = 'hh:mm a';
13
+ export const NUMBERED_TIME_FORMAT = 'hh:mm';
14
+ export const EASY_FORMATS = {
14
15
  date: DEFAULT_DATE_FORMAT,
15
16
  time: DEFAULT_TIME_FORMAT,
16
- full: "".concat(DEFAULT_DATE_FORMAT, " ").concat(DEFAULT_TIME_FORMAT)
17
+ full: `${DEFAULT_DATE_FORMAT} ${DEFAULT_TIME_FORMAT}`,
17
18
  };
18
19
  /**
19
20
  * Formats a date according to date-fns format
@@ -23,47 +24,50 @@ export var EASY_FORMATS = {
23
24
  * - full: dd-MM-yyyy hh:mm a
24
25
  *
25
26
  * @see https://date-fns.org/docs/format
26
- */ export var format = function format(date, providedDateFormat, timezone) {
27
- var dateFormat = providedDateFormat || DEFAULT_DATE_FORMAT;
27
+ */
28
+ export const format = (date, providedDateFormat, timezone) => {
29
+ let dateFormat = providedDateFormat || DEFAULT_DATE_FORMAT;
28
30
  if (dateFormat in EASY_FORMATS) {
29
31
  dateFormat = EASY_FORMATS[dateFormat];
30
32
  }
31
- var newDate = timezone ? toZonedTime(new Date(date), timezone) : new Date(date);
33
+ const newDate = timezone
34
+ ? toZonedTime(new Date(date), timezone)
35
+ : new Date(date);
32
36
  return fnsFormat(newDate, dateFormat);
33
37
  };
34
- export var formatToLocal = function formatToLocal() {
35
- var date = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : new Date(), providedDateFormat = arguments.length > 1 ? arguments[1] : void 0;
38
+ export const formatToLocal = (date = new Date(), providedDateFormat) => {
36
39
  return format(new Date(date), providedDateFormat, config.timezone);
37
40
  };
38
- export var parse = function parse(date) {
41
+ export const parse = (date) => {
39
42
  return fnsParse(date, DEFAULT_DATE_FORMAT, new Date());
40
43
  };
41
- export var ensureExtremityOfDay = function ensureExtremityOfDay(date, startOrEnd, timezone) {
42
- var extremity = startOrEnd === 'end' ? endOfDay : startOfDay;
43
- var tz = timezone || getTimeZone();
44
+ export const ensureExtremityOfDay = (date, startOrEnd, timezone) => {
45
+ const extremity = startOrEnd === 'end' ? endOfDay : startOfDay;
46
+ const tz = timezone || getTimeZone();
44
47
  // First convert date to UTC, apply start of day, then convert back to timezone
45
48
  return fromZonedTime(extremity(toZonedTime(date, tz)), tz);
46
49
  };
47
- export var getTimeZone = function getTimeZone() {
50
+ export const getTimeZone = () => {
48
51
  return config.timezone;
49
52
  };
50
53
  /**
51
54
  *
52
55
  * @param date Date is in UTC and this will convert to a zoned time (00:00:00 => 16:00:00)
53
56
  * @returns
54
- */ export var zonedDate = function zonedDate() {
55
- var date = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : new Date(), timezone = arguments.length > 1 ? arguments[1] : void 0;
57
+ */
58
+ export const zonedDate = (date = new Date(), timezone) => {
56
59
  return fromZonedTime(date, timezone || getTimeZone());
57
60
  };
58
61
  /**
59
62
  *
60
63
  * @param date Date is in UTC and this will convert to a zoned time (16:00:00 => 00:00:00)
61
64
  * @returns
62
- */ export var utcDate = function utcDate() {
63
- var date = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : new Date(), timezone = arguments.length > 1 ? arguments[1] : void 0;
65
+ */
66
+ export const utcDate = (date = new Date(), timezone) => {
64
67
  return toZonedTime(date, timezone || getTimeZone());
65
68
  };
66
- export var setTimeZone = function setTimeZone(timezone) {
69
+ export const setTimeZone = (timezone) => {
67
70
  config.timezone = timezone;
68
71
  };
69
72
  export * from './config.js';
73
+ //# sourceMappingURL=index.js.map
@@ -1,13 +1,15 @@
1
1
  import { singleton } from '@driveflux/singleton';
2
- export var translations = singleton('timeTranslations', {
2
+ export const translations = singleton('timeTranslations', {
3
3
  am: 'am',
4
- pm: 'pm'
4
+ pm: 'pm',
5
5
  });
6
- export var setTranslations = function setTranslations(ts) {
7
- for(var key in ts){
8
- translations[key] = ts[key];
6
+ export const setTranslations = (ts) => {
7
+ for (const key in ts) {
8
+ translations[key] =
9
+ ts[key];
9
10
  }
10
11
  };
11
- export var setTranslation = function setTranslation(key, value) {
12
+ export const setTranslation = (key, value) => {
12
13
  translations[key] = value;
13
14
  };
15
+ //# sourceMappingURL=translations.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driveflux/time",
3
- "version": "6.0.3",
3
+ "version": "6.0.4",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./package.json": "./package.json",
@@ -17,14 +17,14 @@
17
17
  "dist"
18
18
  ],
19
19
  "dependencies": {
20
- "@driveflux/singleton": "3.0.1",
21
- "date-fns": "^4.1.0",
20
+ "@driveflux/singleton": "3.0.2",
21
+ "date-fns": "^4.2.1",
22
22
  "date-fns-tz": "^3.2.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@driveflux/fab": "4.0.1",
26
- "@driveflux/tsconfig": "3.0.1",
27
- "@types/node": "^25.7.0",
25
+ "@driveflux/fab": "4.0.2",
26
+ "@driveflux/tsconfig": "3.0.2",
27
+ "@types/node": "^25.9.1",
28
28
  "del-cli": "^7.0.0",
29
29
  "typescript": "^6.0.3"
30
30
  },