# timestamp-date

> A simple package to convert dates, string dates and timestamps in JavaScript objects to/from JS Date object.

Latest version **1.6.0** (published 2025-08-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install timestamp-date
pnpm add timestamp-date
yarn add timestamp-date
bun add timestamp-date
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.6.0 |
| Published | 2025-08-25 |
| First published | 2020-02-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 18.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Moses Godson |
| Maintainers | tumba, hansanker77 |
| Keywords | timestamp, js date, firebase, timestamp to date, javascript date, cloud firestore, callable functions |

## Links

- npm: https://www.npmjs.com/package/timestamp-date
- Repository: https://github.com/Moses270/timestamp-date
- Homepage: https://anchorsolutions.nl
- Issues: https://github.com/Moses270/timestamp-date/issues
- npm.io page: https://npm.io/package/timestamp-date

## Dependencies (2)

- [tslib](https://npm.io/package/tslib.md) ^2.8.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.21

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 1.6.0 (latest) — 2025-08-25
- 1.5.7 — 2023-11-07
- 1.5.6 — 2023-11-07
- 1.5.5 — 2023-11-07
- 1.5.4 — 2023-11-07
- 1.5.3 — 2023-11-07
- 1.5.2 — 2023-11-07
- 1.5.1 — 2023-09-13
- 1.5.0 — 2023-09-13
- 1.1.9 — 2023-09-13
- 1.3.0 — 2021-11-08
- 1.2.5 — 2021-10-17
- 1.2.4 — 2021-09-25
- 1.2.3 — 2021-09-25
- 1.2.2 — 2021-09-25
- … 22 more at https://npm.io/package/timestamp-date/versions

## README

# TimestampDate

TimestampDate is a simple date-timestamp tool provided by [Anchor Solutions](https://www.anchorsolutions.nl) to convert dates, string dates and timestamps in JavaScript objects to/from JS Date object. It can recursively parse the object document tree presented to locate each timestamp or date values and then convert to the expected type.

## Installation
Install timestamp-date via npm by running the following command: 
> `npm install timestamp-date --save`

## Usage
Create and instance and call available methods from the instance created.

 ```typescript
import { TimestampDate } from 'timestamp-date';

const timestampDate = new TimestampDate();
 ``` 

### Use `TimestampDate` utilities functions
```typescript
// converts all timestamp in doc to js date
const doc = {
  a: {},
  b: {
    c: [
      d: <Timestamp>
    ],
    e: <Timestamp>
  }
};

const updated = this.timestampService.parseTimestampToDate(doc);

console.log(doc, updated);
```

### Methods
| Method Name | Params  | Return type | Description                                        |
|-------------|---------|-------------|----------------------------------------------------|
| getServerTimestamp     |           | Timestamp      | Gets current timestamp value representative from firebase.|
|getServerDate||Date|Gets current date value from firebase|
| timestampToDate        | Timestamp  | Date           | Converts timestamp object to date object |
| dateToTimestamp        | Date  | Timestamp        | Converts JS date object to timestamp                      |
| parseTimestampToDate<T, R>    | <T> | <R>       | Recursively iterates through properties of a JS object and converts all occurences of timestamp to normal JS Date|
| parseDateToTimestamp<T, R>    | <T> | <R>       | Recursively iterates through properties of a JS object and converts all occurences of JS Date to timestamp object|
| parseStringToDate<T, R>    | <T> | <R>       | Recursively iterates through properties of a JS object and converts all occurences of valid date string values to JavaScript Date objects|
| parseDateToString<T, R>    | <T> | <R>       | Recursively iterates through properties of a JS object and converts all occurences of JS Date to date strings types.|

### Further Reading
Have a look at other packages by [Anchor Solutions](https://www.anchorsolutions.nl):
- [Pincode](https://www.npmjs.com/package/pincode)
- [translator-client-module](https://www.npmjs.com/package/translator-client-module)
- [MatModal](https://www.npmjs.com/package/mat-modal)

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