@finema/core 2.56.0 → 2.56.1

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/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finema/core",
3
- "version": "2.56.0",
3
+ "version": "2.56.1",
4
4
  "configKey": "core",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
package/dist/module.mjs CHANGED
@@ -4,7 +4,7 @@ import * as lodash from 'lodash-es';
4
4
  import * as theme from '../dist/runtime/theme/index.js';
5
5
 
6
6
  const name = "@finema/core";
7
- const version = "2.56.0";
7
+ const version = "2.56.1";
8
8
 
9
9
  const nuxtAppOptions = {
10
10
  head: {
@@ -16,6 +16,7 @@
16
16
  :start-time="startTime"
17
17
  :teleport="teleport"
18
18
  :required="required"
19
+ :timezone="appConfig.core?.time_zone"
19
20
  :flow="['calendar', 'time']"
20
21
  @update:model-value="onInput"
21
22
  >
@@ -119,13 +120,19 @@ onMounted(() => {
119
120
  });
120
121
  const format = (date) => {
121
122
  if (props.disabledTime) {
122
- return TimeHelper.displayDate(date);
123
+ return TimeHelper.displayDate(date, {
124
+ autoTimezone: true
125
+ });
123
126
  }
124
- return TimeHelper.displayDateTime(date);
127
+ return TimeHelper.displayDateTime(date, {
128
+ autoTimezone: true
129
+ });
125
130
  };
126
131
  const onInput = (_value) => {
127
132
  if (props.disabledTime && !props.isReturnISO) {
128
- value.value = TimeHelper.getDateFormTime(_value);
133
+ value.value = TimeHelper.displayDate(_value, {
134
+ autoTimezone: true
135
+ }) ?? void 0;
129
136
  } else {
130
137
  value.value = _value;
131
138
  }
@@ -64,9 +64,10 @@
64
64
  <script setup>
65
65
  import Datepicker from "@vuepic/vue-datepicker";
66
66
  import FieldWrapper from "#core/components/Form/FieldWrapper.vue";
67
- import { TimeHelper, ref, useFieldHOC, useAppConfig, computed, useUiConfig, watch, onMounted } from "#imports";
67
+ import { ref, useFieldHOC, useAppConfig, computed, useUiConfig, watch, onMounted, TimeHelper } from "#imports";
68
68
  import "@vuepic/vue-datepicker/dist/main.css";
69
69
  import { dateTimeTheme } from "#core/theme/dateTime";
70
+ import { toZonedTime } from "date-fns-tz";
70
71
  const emits = defineEmits(["change"]);
71
72
  const props = defineProps({
72
73
  isDisabledMultiCalendar: { type: Boolean, required: false },
@@ -103,18 +104,18 @@ const {
103
104
  const innerValueRef = ref([]);
104
105
  const initializeValue = () => {
105
106
  const currentValue = value.value;
106
- if (currentValue) {
107
- const start = typeof currentValue.start === "string" ? new Date(currentValue.start) : currentValue.start;
108
- const end = typeof currentValue.end === "string" ? new Date(currentValue.end) : currentValue.end;
107
+ if (currentValue && currentValue.start) {
108
+ const start = toZonedTime(new Date(currentValue.start), appConfig.core.time_zone);
109
+ const end = toZonedTime(new Date(currentValue.end || currentValue.start), appConfig.core.time_zone);
109
110
  innerValueRef.value = [start, end];
110
111
  } else {
111
112
  innerValueRef.value = [];
112
113
  }
113
114
  };
114
115
  watch(value, (newValue) => {
115
- if (newValue && (newValue.start || newValue.end)) {
116
- const start = typeof newValue.start === "string" ? new Date(newValue.start) : newValue.start;
117
- const end = typeof newValue.end === "string" ? new Date(newValue.end) : newValue.end;
116
+ if (newValue && newValue.start) {
117
+ const start = toZonedTime(new Date(newValue.start), appConfig.core.time_zone);
118
+ const end = toZonedTime(new Date(newValue.end || newValue.start), appConfig.core.time_zone);
118
119
  innerValueRef.value = [start, end];
119
120
  } else if (!newValue) {
120
121
  innerValueRef.value = [];
@@ -127,11 +128,25 @@ onMounted(() => {
127
128
  });
128
129
  const format = (date) => {
129
130
  if (props.disabledTime) {
130
- return date.length > 0 ? TimeHelper.displayDate(date[0]) + " - " + TimeHelper.displayDate(date[1] ?? date[0]) : "";
131
+ return date.length > 0 && date[0] ? TimeHelper.displayDate(date[0], {
132
+ autoTimezone: true
133
+ }) + " - " + TimeHelper.displayDate(date[1] || date[0], {
134
+ autoTimezone: true
135
+ }) : "";
131
136
  }
132
- return date.length > 0 ? TimeHelper.displayDateTime(date[0]) + " - " + TimeHelper.displayDateTime(date[1] ?? date[0]) : "";
137
+ return date.length > 0 && date[0] ? TimeHelper.displayDateTime(date[0], {
138
+ autoTimezone: true
139
+ }) + " - " + TimeHelper.displayDateTime(date[1] || date[0], {
140
+ autoTimezone: true
141
+ }) : "";
133
142
  };
134
143
  const onInput = (_value) => {
144
+ const formattedDates = _value.map((d) => {
145
+ const year = d.getFullYear();
146
+ const month = String(d.getMonth() + 1).padStart(2, "0");
147
+ const day = String(d.getDate()).padStart(2, "0");
148
+ return `${year}-${month}-${day}`;
149
+ });
135
150
  if (_value === null || _value === void 0) {
136
151
  value.value = void 0;
137
152
  emits("change", void 0);
@@ -139,8 +154,8 @@ const onInput = (_value) => {
139
154
  }
140
155
  if (props.disabledTime && !props.isReturnISO) {
141
156
  value.value = {
142
- start: TimeHelper.getDateFormTime(_value[0]),
143
- end: TimeHelper.getDateFormTime(_value[1] || _value[0])
157
+ start: formattedDates[0],
158
+ end: formattedDates[1] || formattedDates[0]
144
159
  };
145
160
  } else {
146
161
  value.value = {
@@ -15,6 +15,7 @@
15
15
  :required="wrapperProps.required"
16
16
  :clearable="true"
17
17
  :always-clearable="true"
18
+ :timezone="appConfig.core?.time_zone"
18
19
  @update:model-value="onInput"
19
20
  >
20
21
  <template
@@ -15,6 +15,7 @@
15
15
  :start-time="startTime"
16
16
  :required="required"
17
17
  :enable-seconds="enableSeconds"
18
+ :timezone="appConfig.core?.time_zone"
18
19
  @update:model-value="onChange"
19
20
  >
20
21
  <template #dp-input="{ value: innerValue }">
@@ -1,10 +1,20 @@
1
1
  export declare class TimeHelper {
2
2
  static thaiFormat: (dateStr: Date, formatStr: string, forceThai?: boolean) => string;
3
- static displayDate: (time: string | Date | null | undefined) => string | null;
4
- static displayDateTime: (time: string | Date | null | undefined) => string | null;
5
- static displayDateThai: (time: string | Date | null | undefined) => string | null;
6
- static displayDateTimeThai: (time: string | Date | null | undefined) => string | null;
7
- static displayDateRange: (startDate: Date | string | null | undefined, endDate: Date | string | null | undefined) => {
3
+ static displayDate: (time: string | Date | null | undefined, options?: {
4
+ autoTimezone?: boolean;
5
+ }) => string | null;
6
+ static displayDateTime: (time: string | Date | null | undefined, options?: {
7
+ autoTimezone?: boolean;
8
+ }) => string | null;
9
+ static displayDateThai: (time: string | Date | null | undefined, options?: {
10
+ autoTimezone?: boolean;
11
+ }) => string | null;
12
+ static displayDateTimeThai: (time: string | Date | null | undefined, options?: {
13
+ autoTimezone?: boolean;
14
+ }) => string | null;
15
+ static displayDateRange: (startDate: Date | string | null | undefined, endDate: Date | string | null | undefined, options?: {
16
+ autoTimezone?: boolean;
17
+ }) => {
8
18
  startDate: Date | string | null;
9
19
  endDate: Date | string | null;
10
20
  };
@@ -25,39 +25,55 @@ export class TimeHelper {
25
25
  }
26
26
  return formatInTimeZone(newDateStr, timeZone, formatStr, options);
27
27
  };
28
- static displayDate = (time) => {
28
+ static displayDate = (time, options) => {
29
29
  if (!time) {
30
30
  return null;
31
31
  }
32
32
  const parsedTime = getTime(time);
33
+ if (options?.autoTimezone) {
34
+ const newTime2 = format(parsedTime, dateFormatDisplay);
35
+ return isValid(parsedTime) ? newTime2 : time;
36
+ }
33
37
  const newTime = TimeHelper.thaiFormat(parsedTime, dateFormatDisplay);
34
38
  return isValid(parsedTime) ? newTime : time;
35
39
  };
36
- static displayDateTime = (time) => {
40
+ static displayDateTime = (time, options) => {
37
41
  if (!time) {
38
42
  return null;
39
43
  }
40
44
  const parsedTime = getTime(time);
45
+ if (options?.autoTimezone) {
46
+ const newTime2 = format(parsedTime, dateTimeFormatDisplay);
47
+ return isValid(parsedTime) ? newTime2 : time;
48
+ }
41
49
  const newTime = TimeHelper.thaiFormat(parsedTime, dateTimeFormatDisplay);
42
50
  return isValid(parsedTime) ? newTime : time;
43
51
  };
44
- static displayDateThai = (time) => {
52
+ static displayDateThai = (time, options) => {
45
53
  if (!time) {
46
54
  return null;
47
55
  }
48
56
  const parsedTime = getTime(time);
57
+ if (options?.autoTimezone) {
58
+ const newTime2 = format(parsedTime, dateFormat);
59
+ return isValid(parsedTime) ? newTime2 : time;
60
+ }
49
61
  const newTime = TimeHelper.thaiFormat(parsedTime, dateFormat, true);
50
62
  return isValid(parsedTime) ? newTime : time;
51
63
  };
52
- static displayDateTimeThai = (time) => {
64
+ static displayDateTimeThai = (time, options) => {
53
65
  if (!time) {
54
66
  return null;
55
67
  }
56
68
  const parsedTime = getTime(time);
69
+ if (options?.autoTimezone) {
70
+ const newTime2 = format(parsedTime, dateTimeFormat);
71
+ return isValid(parsedTime) ? newTime2 : time;
72
+ }
57
73
  const newTime = TimeHelper.thaiFormat(parsedTime, dateTimeFormat, true);
58
74
  return isValid(parsedTime) ? newTime : time;
59
75
  };
60
- static displayDateRange = (startDate, endDate) => {
76
+ static displayDateRange = (startDate, endDate, options) => {
61
77
  if (!startDate || !endDate) {
62
78
  return {
63
79
  startDate: startDate || null,
@@ -66,6 +82,14 @@ export class TimeHelper {
66
82
  }
67
83
  const parsedStartDate = getTime(startDate);
68
84
  const parsedEndDate = getTime(endDate);
85
+ if (options?.autoTimezone) {
86
+ const newTimeStartDate = format(parsedStartDate, dateFormatDisplay);
87
+ const newTimeEndDate = format(parsedEndDate, dateFormatDisplay);
88
+ return {
89
+ startDate: isValid(parsedStartDate) ? newTimeStartDate : startDate,
90
+ endDate: isValid(parsedEndDate) ? newTimeEndDate : endDate
91
+ };
92
+ }
69
93
  const newStartDate = TimeHelper.thaiFormat(parsedStartDate, dateFormatDisplay);
70
94
  const newEndDate = TimeHelper.thaiFormat(parsedEndDate, dateFormatDisplay);
71
95
  return {
@@ -105,7 +129,7 @@ export class TimeHelper {
105
129
  return null;
106
130
  }
107
131
  const parsedTime = getTime(time);
108
- const newTime = format(parsedTime, customFormat);
132
+ const newTime = formatInTimeZone(parsedTime, timeZone, customFormat);
109
133
  return isValid(parsedTime) ? newTime : time;
110
134
  };
111
135
  static getDateFormTimeWithLocal = (time, customFormat = dateFormat) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finema/core",
3
- "version": "2.56.0",
3
+ "version": "2.56.1",
4
4
  "repository": "https://gitlab.finema.co/finema/ui-kit",
5
5
  "license": "MIT",
6
6
  "author": "Finema Dev Core Team",