diginet-core-ui 1.4.53 → 1.4.54-beta.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/theme/settings.js CHANGED
@@ -3,6 +3,7 @@ import { font } from "../styles/font";
3
3
  import { typography as typographies } from "../styles/typography";
4
4
  import createTheme from "./createTheme";
5
5
  import locale from "../locale";
6
+ import { getFormatDateByCountry, getDecimalSymbolByCountry } from "../utils/getLang";
6
7
  // import { getGlobal } from 'global';
7
8
  const {
8
9
  fontSize,
@@ -345,7 +346,7 @@ const settings = {
345
346
  className: '',
346
347
  disabled: false,
347
348
  error: '',
348
- format: locale.get() === 'vi' ? 'DD/MM/YYYY' : 'DD/MM/YYYY',
349
+ format: getFormatDateByCountry(locale.get()),
349
350
  label: '',
350
351
  readOnly: false,
351
352
  required: false,
@@ -360,7 +361,7 @@ const settings = {
360
361
  controls: false,
361
362
  disabled: false,
362
363
  displayAnotherMonth: true,
363
- displayFormat: locale.get() === 'vi' ? 'DD/MM/YYYY' : 'MM/DD/YYYY',
364
+ displayFormat: getFormatDateByCountry(locale.get()),
364
365
  pressESCToClose: true,
365
366
  readOnly: false,
366
367
  required: false,
@@ -596,7 +597,7 @@ const settings = {
596
597
  autoFocus: false,
597
598
  className: '',
598
599
  decimalDigit: Infinity,
599
- decimalSymbol: locale.get() === 'vi' ? ',' : '.',
600
+ decimalSymbol: getDecimalSymbolByCountry(locale.get()),
600
601
  disabled: false,
601
602
  disabledNegative: false,
602
603
  endIcon: '',
@@ -0,0 +1,69 @@
1
+ import { format } from 'date-fns';
2
+ import { lowerCaseDayYear } from "../components/form-control/date-input/utils";
3
+ import { enUS, zhCN, vi, ja } from 'date-fns/locale';
4
+ const getFormatDateByCountry = (lang, isDateFns = false) => {
5
+ let result = '';
6
+ switch (lang) {
7
+ case 'en':
8
+ result = isDateFns ? enUS : 'MM/DD/YYYY';
9
+ break;
10
+ case 'zh':
11
+ result = isDateFns ? zhCN : 'YYYY/MM/DD';
12
+ break;
13
+ case 'ja':
14
+ result = isDateFns ? ja : 'YYYY/MM/DD';
15
+ break;
16
+ case 'vi':
17
+ result = isDateFns ? vi : 'DD/MM/YYYY';
18
+ break;
19
+ default:
20
+ result = 'DD/MM/YYYY';
21
+ break;
22
+ }
23
+ return result;
24
+ };
25
+ const parseDateString = (date, formatStr, locale) => {
26
+ return format(date, lowerCaseDayYear(formatStr), {
27
+ locale: getFormatDateByCountry(locale, true)
28
+ });
29
+ };
30
+ const getDecimalSymbolByCountry = lang => {
31
+ let result = '';
32
+ switch (lang) {
33
+ case 'vi': // Việt Nam
34
+ case 'de': // Đức
35
+ case 'fr': // Pháp
36
+ case 'it': // Ý
37
+ case 'es': // Tây Ban Nha
38
+ case 'ru':
39
+ // Nga
40
+ result = ','; // Dấu phẩy làm thập phân
41
+ break;
42
+ case 'en': // Anh, Mỹ
43
+ case 'zh': // Trung Quốc
44
+ case 'ja': // Nhật Bản
45
+ default:
46
+ result = '.'; // Dấu chấm làm thập phân
47
+ break;
48
+ }
49
+ return result;
50
+ };
51
+ const getThousandSeparatorByCountry = lang => {
52
+ switch (lang) {
53
+ case 'vi': // Việt Nam
54
+ case 'de': // Đức
55
+ case 'es':
56
+ // Tây Ban Nha
57
+ return '.';
58
+ case 'fr':
59
+ // Pháp
60
+ return '\u00A0';
61
+ // space không ngắt
62
+ case 'en': // Anh, Mỹ
63
+ case 'zh': // Trung Quốc
64
+ case 'ja': // Nhật
65
+ default:
66
+ return ',';
67
+ }
68
+ };
69
+ export { getFormatDateByCountry, parseDateString, getDecimalSymbolByCountry, getThousandSeparatorByCountry };
package/utils/index.js CHANGED
@@ -35,4 +35,5 @@ export * from "./sb-template";
35
35
  export * from "./string/string";
36
36
  export * from "./validate";
37
37
  export * from "./object/object";
38
+ export * from "./getLang";
38
39
  export default utils;