> For the complete documentation index, see [llms.txt](https://tech.x2bee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tech.x2bee.com/dev-guide/developer-guide-en/dev-start/images-and-media/number-and-date-conversion-guide.md).

# Number and Date Conversion Guide

Provides a guide to the number and date conversion methods used in the X2BEE solution. Explains the number conversion guidelines for Front and BO, as well as date conversion examples and expected results.

***

## Number Conversion Guide

#### BO Number Conversion Guide (format-number.ts)

```ts
export function fNumber(inputValue: InputNumberValue, options?: Options) {
  const locale = formatNumberLocale() || DEFAULT_LOCALE
  const number = processInput(inputValue)
  if (number === null) return ''
  const fm = new Intl.NumberFormat(locale.code, {
    minimumFractionDigits: 0,
    maximumFractionDigits: 2,
    ...options
  }).format(number)
  return fm
}
```

Sample

* fNumber(24000000) — Result: 24,000,000

***

## Date Conversion Guide

#### BO Date Conversion Guide (common-utils.ts)

```ts
/**
 * 날짜 변환
 * Format을 사용자 지정
 */
export const convertFormatDate = (value: ConfigType, formatValue: string) =>
  dayjs(value).format(formatValue)

/**
 * 날짜 변환 Type1
 * Format YYYY-MM-DD HH:mm:ss
 */
export const convertLocaleDateTime = (date: ConfigType) =>
  dayjs(date).format(DATE_FORMAT.LOCAL_DATE_TIME)

/**
 * 날짜 변환 Type2
 * Format YYYY-MM-DD
 */
export const convertLocaleDate = (date: ConfigType) =>
  dayjs(date).format(DATE_FORMAT.DEFAULT.DATE)
```

Sample

* convertFormatDate('2023-06-12T09:52:16', 'YYYY-MM-DD HH:mm');\
  Result: 2023-06-12 09:52
* convertLocaleDateTime('2023-06-12T09:52:16');\
  Result: 2023-06-12 09:52:16

{% hint style="info" %}

#### BO Locale

Applies the `LocalizationProvider` provided within MUI and uses the `@mui/x-date-pickers` component.

When the language set is changed, it automatically converts to the Date Format corresponding to the changed language set.

For how to apply `LocalizationProvider`, refer to the following documentation:\
<https://mui.com/x/react-date-pickers/adapters-locale/>
{% endhint %}

***

#### BO Date Pattern Constants (common-constants.ts)

```ts
export const DATE_FORMAT = {
  DATE_TIME: 'DD MMM YYYY h:mm a',
  DATE: 'DD MMM YYYY',
  TIME: 'h:mm a',
  LOCAL_DATE_TIME: 'YYYY-MM-DDTHH:mm:ss',
  SPLIT: {
    DATE_TIME: 'DD/MM/YYYY h:mm a',
    DATE: 'DD/MM/YYYY'
  },
  DEFAULT: {
    DATE_TIME: 'YYYY-MM-DD HH:mm:ss',
    DATE_TIME_WITH_MINUTE: 'YYYY-MM-DD HH:mm',
    DATE: 'YYYY-MM-DD',
    DOT_DATE: 'YYYY.MM.DD',
    DATE_STRING: 'YYYYMMDD',
    MONTH: 'YYYY-MM'
  },
  PARAM_CASE: {
    DATE_TIME: 'DD-MM-YYYY h:mm a',
    DATE: 'DD-MM-YYYY'
  }
}
```

Sample

* convertFormatDate('2023-06-12T09:52:16', DATE\_FORMAT.DEFAULT.DATE\_TIME\_WITH\_MINUTE);\
  Result: 2023-06-12 09:52
* convertFormatDate('2023-06-12T09:52:16', DATE\_FORMAT.DEFAULT.DATE\_TIME);\
  Result: 2023-06-12 09:52:16

***

#### Date Pattern Types

You can use the expressions below by putting them into the format.

| Token | Example Output   | Description                       |
| ----- | ---------------- | --------------------------------- |
| YY    | 01               | Two-digit year                    |
| YYYY  | 2001             | Four-digit year                   |
| M     | 1-12             | Month, beginning at 1             |
| MM    | 01-12            | Month, 2-digits                   |
| MMM   | Jan-Dec          | The abbreviated month name        |
| MMMM  | January-December | The full month name               |
| D     | 1-31             | Day of month                      |
| DD    | 01-31            | Day of month, 2-digits            |
| H     | 0-23             | Hours                             |
| HH    | 00-23            | Hours, 2-digits                   |
| h     | 1-12             | Hours, 12-hour clock              |
| hh    | 01-12            | Hours, 12-hour clock, 2-digits    |
| m     | 0-59             | Minutes                           |
| mm    | 00-59            | Minutes, 2-digits                 |
| s     | 0-59             | Seconds                           |
| ss    | 00-59            | Seconds, 2-digits                 |
| S     | 0-9              | Hundreds of milliseconds, 1-digit |
| SS    | 00-99            | Tens of milliseconds, 2-digits    |
| SSS   | 000-999          | Milliseconds, 3-digits            |
| Z     | -05:00           | Offset from UTC                   |
| ZZ    | -0500            | Compact offset from UTC, 2-digits |
| A     | AM PM            | Post or ante meridiem, upper-case |
| a     | am pm            | Post or ante meridiem, lower-case |
| Do    | 1st...31st       | Day of Month with ordinal         |
| X     | 1410715640.579   | Unix timestamp (seconds)          |
| x     | 1410715640579    | Unix timestamp (ms)               |
