# microcms-utils

> microCMS useful utilities

Latest version **0.0.14** (published 2023-06-08) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install microcms-utils
pnpm add microcms-utils
yarn add microcms-utils
bun add microcms-utils
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.14 |
| Published | 2023-06-08 |
| First published | 2023-05-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 86.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | microCMS |
| Maintainers | himorishige |
| Keywords | microCMS |

## Links

- npm: https://www.npmjs.com/package/microcms-utils
- npm.io page: https://npm.io/package/microcms-utils

## Recent versions

- 0.0.14 (latest) — 2023-06-08
- 0.0.13 — 2023-06-08
- 0.0.12 — 2023-06-08
- 0.0.11 — 2023-06-03
- 0.0.10 — 2023-06-03
- 0.0.9 — 2023-06-03
- 0.0.8 — 2023-06-01
- 0.0.7 — 2023-05-27
- 0.0.6 — 2023-05-21
- 0.0.5 — 2023-05-21
- 0.0.4 — 2023-05-21
- 0.0.3 — 2023-05-21
- 0.0.2 — 2023-05-21
- 0.0.1 — 2023-05-21

## README

# microCMS Utilities

## Date utility

`microCMS API` returns the date and time in UTC as the timezone.  
If you want to retrieve a date or time in Japan time, you have to convert it to UTC each time.  
`microcms-utils` date utility provides functions to make working with the API easier.

### getAbsoluteTime

You can get the date and time independent of the time zone of the execution environment.

```ts
import { getAbsoluteTime } from 'microcms-utils'

// Local time dependent on execution environment is displayed. ex. UTC Runtime
const dateTime = new Date().toISOString().toLocaleString();
// 2023-06-01T01:14:53.838Z

// Local time in the specified time difference is displayed.
const absoluteDateTime = getAbsoluteTime(new Date().toISOString(), 9).toLocaleString();
// 2023/6/1 10:14:53
```

### getStartAndEndOfTime

You can get a range of dates, months and years independent of the time zone of the execution environment.

#### day

```ts
import { getStartAndEndOfTime } from 'microcms-utils';

const [start, end] = getStartAndEndOfTime('2023-05-01');

// start: 2023-04-30T14:59:59.999Z
// end: 2023-05-01T15:00:00.000Z
```

```ts
// range option
const [start, end] = getStartAndEndOfTime('2023-06-01', {
  range: 3, // 3 days
}),

// start: 2023-05-29T14:59:59.999Z
// end: 2023-06-01T15:00:00.000Z
```

#### month

```ts
import { getStartAndEndOfTime } from 'microcms-utils';

const [start, end] = getStartAndEndOfTime('2023-05');

// start: 2023-04-30T14:59:59.999Z
// end: 2023-05-31T15:00:00.000Z
```

```ts
// range option
const [start, end] = getStartAndEndOfTime('2023-06', {
  range: 3, // 3 months
}),

// start: 2023-03-31T14:59:59.999Z
// end: 2023-06-30T15:00:00.000Z
```

#### year

```ts
import { getStartAndEndOfTime } from 'microcms-utils';

const [start, end] = getStartAndEndOfTime('2023');

// start: 2022-12-31T14:59:59.999Z
// end: 2023-12-31T15:00:00.000Z
```

```ts
// range option
const [start, end] = getStartAndEndOfTime('2023', {
  range: 3, // 3 years
}),

// start: 2020-12-31T14:59:59.999Z
// end: 2023-12-31T15:00:00.000Z
```

### getFormattedFilterTimeRange

You may get a query for filters string.

```ts
import { getFormattedFilterTimeRange } from 'microcms-utils';

const queryString = getFormattedFilterTimeRange('fieldName', '2023-05');

// fieldName[greater_than]2023-04-30T14:59:59.999Z[and]fieldName[less_than]2023-05-31T15:00:00.000Z

const rangedQueryString = getFormattedFilterTimeRange('fieldName', '2023-06', {
  range: 2, // 2 months
});

// fieldName[greater_than]2023-04-30T14:59:59.999Z[and]fieldName[less_than]2023-06-30T15:00:00.000Z
```

---
_Source: https://npm.io/package/microcms-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
