@driveflux/time 5.0.0 → 5.0.2

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,13 @@
1
1
  import { singleton } from '@driveflux/singleton';
2
- var getConfig = function() {
3
- return {
4
- timezone: process.env.TIME_ZONE || 'Asia/Kuala_Lumpur'
5
- };
6
- };
7
- export var config = singleton('timeConfig', getConfig());
8
- export var resetConfig = function() {
2
+ const getConfig = () => ({
3
+ timezone: process.env.TIME_ZONE || 'Asia/Kuala_Lumpur',
4
+ });
5
+ export let config = singleton('timeConfig', getConfig());
6
+ export const resetConfig = () => {
9
7
  config = singleton('timeConfig', getConfig(), true);
10
8
  return config;
11
9
  };
12
- export var setConfig = function(key, value) {
10
+ export const setConfig = (key, value) => {
13
11
  config[key] = value;
14
12
  };
13
+ //# sourceMappingURL=config.js.map
package/dist/index.js CHANGED
@@ -4,16 +4,17 @@ import { format as fnsFormat } from 'date-fns/format';
4
4
  import { parse as fnsParse } from 'date-fns/parse';
5
5
  import { startOfDay } from 'date-fns/startOfDay';
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(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() {
35
- var date = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : new Date(), timezone = arguments.length > 1 ? arguments[1] : void 0;
38
+ export const formatToLocal = (date = new Date(), timezone) => {
36
39
  return format(new Date(date), undefined, timezone || config.timezone);
37
40
  };
38
- export var parse = function(date) {
41
+ export const parse = (date) => {
39
42
  return fnsParse(date, DEFAULT_DATE_FORMAT, new Date());
40
43
  };
41
- export var ensureExtremityOfDay = function(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() {
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() {
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() {
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(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(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(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": "5.0.0",
3
+ "version": "5.0.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./package.json": "./package.json",
@@ -17,13 +17,13 @@
17
17
  "dist"
18
18
  ],
19
19
  "dependencies": {
20
- "@driveflux/singleton": "2.0.0",
20
+ "@driveflux/singleton": "2.0.2",
21
21
  "date-fns": "^4.1.0",
22
22
  "date-fns-tz": "^3.2.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@driveflux/fab": "3.0.0",
26
- "@driveflux/tsconfig": "2.0.0",
25
+ "@driveflux/fab": "3.0.2",
26
+ "@driveflux/tsconfig": "2.0.2",
27
27
  "@types/node": "^22.15.16",
28
28
  "del-cli": "^6.0.0",
29
29
  "typescript": "^5.8.3"