# @splunk/moment

> Splunk timezone and formatting plugins for moment.js

Latest version **0.7.0** (published 2024-02-07) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @splunk/moment
pnpm add @splunk/moment
yarn add @splunk/moment
bun add @splunk/moment
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.7.0 |
| Published | 2024-02-07 |
| First published | 2019-10-14 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=14 |
| Dependencies | 3 |
| Unpacked size | 514.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Splunk Inc. |
| Maintainers | splunker, splunk_sui_publish |

## Links

- npm: https://www.npmjs.com/package/@splunk/moment
- npm.io page: https://npm.io/package/@splunk/moment

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) ^4.17.14
- [@splunk/ui-utils](https://npm.io/package/@splunk/ui-utils.md) ^1.6.0
- [@splunk/splunk-utils](https://npm.io/package/@splunk/splunk-utils.md) ^3.0.0

## Recent versions

- 0.7.0 (latest) — 2024-02-07
- 0.6.1 — 2022-12-06
- 0.6.0 — 2021-02-05
- 0.5.2 — 2020-02-05
- 0.5.1 — 2019-10-14

## README

# @splunk/moment

A package of [Moment](http://momentjs.com/) and [Moment Timezone](http://momentjs.com/timezone)
plugins for Splunk Enterprise timezones, and formatting for locales with second and millisecond precision.

## Install

Install the package:
```
npm install @splunk/moment
```

## Usage

Import moment from the Splunk UI package. This provides a Moment class with the timezone and
timezone util plugins.
```js
import moment from '@splunk/moment';
```

Create new moment instances in the server timezone and locale.
```js
const time1 = moment.newSplunkTime({time: 1490500800});
const time2 = moment.newSplunkTime({time: '10/10/2017', format: 'l'});
```

Manipulate and query times using the [Moment](http://momentjs.com/docs/) API.
```js
time1.subtract(1, 'day').startOf('day';);
const isBefore = time1.isBefore(time2);
```

Format Times using second or millisecond precision
```js
const displayValue = time1.splunkFormat('lls');
```

## Advanced Usage

If used in an environment without the `window.$C` properties set by `splunkweb`, there are
functions to setup and use the plugins with raw timezone data from Splunk Enterprise.

The timezone data can be retrieved from `services/search/timeparser/tz`. *To access this
service from the client, the endpoint must be exposed in web.conf.*

For example:
```
http://localhost:8000/en-US/splunkd/__raw/services/search/timeparser/tz
```

Set this data as the default Splunk Enterprise timezone, which can be used for creating and manipulating times.
```js
const splunkTimezoneName = moment.setDefaultSplunkTimezone(zoneData);

const time = moment.newSplunkTime({time: 1490500800}); // uses the default timezone
const nowInTokyo = moment.tz('Asia/Tokyo').locale('ja_JP');
const nowAtServer = nowInTokyo.clone().tz(splunkTimezoneName).locale('en_US');
```

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