# date-from-timezone

> Construct dates with timezone context

Latest version **3.0.1** (published 2023-01-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install date-from-timezone
pnpm add date-from-timezone
yarn add date-from-timezone
bun add date-from-timezone
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2023-01-17 |
| First published | 2017-06-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 2 |
| Unpacked size | 12.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Mariusz Nowak |
| Maintainers | medikoo |
| Keywords | date, datetime, i18n, iana, intl, moment, olson, time, timezone |

## Links

- npm: https://www.npmjs.com/package/date-from-timezone
- Repository: https://github.com/medikoo/date-from-timezone
- Homepage: https://github.com/medikoo/date-from-timezone#readme
- Issues: https://github.com/medikoo/date-from-timezone/issues
- npm.io page: https://npm.io/package/date-from-timezone

## Dependencies (2)

- [d](https://npm.io/package/d.md) ^1.0.1
- [es5-ext](https://npm.io/package/es5-ext.md) ^0.10.62

## 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

- 3.0.1 (latest) — 2023-01-17
- 3.0.0 — 2019-02-05
- 2.2.0 — 2018-01-11
- 2.1.1 — 2017-08-31
- 2.1.0 — 2017-08-29
- 2.0.2 — 2017-06-05
- 2.0.1 — 2017-06-02
- 2.0.0 — 2017-06-01
- 1.0.1 — 2017-06-01
- 1.0.0 — 2017-06-01

## README

[![Build status][build-image]][build-url]
[![Tests coverage][cov-image]][cov-url]
[![npm version][npm-image]][npm-url]

# date-from-timezone

## Construct date instances within timezone context or resolve date/time information for given timezone

Having **timezone** and **date & time information** resolve **regular date instance that reflects given time point**, or
having **timezone** and **date instance** resolve **date & time information for given timezone**.

Light implementation which resolves needed data through natively available (in all modern engines, both browsers and Node.js) [Intl.DateTimeFormat](http://www.ecma-international.org/ecma-402/1.0/#sec-12.1).

_If loaded in environment which does not provide `Intl.DateTimeFormat` or of which support is incomplete, module resolves to `null`_

### Examples

#### Construct date instances in specific timezone context

```javascript
var dateFromTimezone = require("date-from-timezone");

var getWarsawDate = dateFromTimezone("Europe/Warsaw");
var getShanghaiDate = dateFromTimezone("Asia/Shanghai");

// Signature of getXDate follows: Date(yearOrTimeValue[, month[, date[, hour[, minutes[, seconds[, milliseconds]]]]])
var warsawNoon = getWarsawDate(2017, 6, 5, 12);
// also e.g.
warsawNoon = getWarsawDate(Date.parse("7/5/2017 12:00:00 PM"));

var shanghaiNoon = getShanghaiDate(2017, 6, 5, 12);

console.log(warsawNoon.toISOString()); // "2017-07-05T10:00:00.000Z" (12PM in Warsaw was at 10AM UTC)
console.log(shanghaiNoon.toISOString()); // "2017-07-05T04:00:00.000Z" (12PM in Shanghai was at 4AM UTC)
```

#### Resolve date & time information for given timezone

```javascript
var getTokenize = require("date-from-timezone/get-tokenize");

var warsawTokenize = getTokenize("Europe/Warsaw");
var shanghaiTokenize = getTokenize("Asia/Shanghai");

console.log(warsawTokenize(new Date(Date.UTC(2017, 6, 5, 10))));
// { year: 2017, month 6, date: 5, hours: 12, minutes: 0, seconds: 0, milliseconds: 0 }

console.log(shanghaiTokenize(new Date(Date.UTC(2017, 6, 5, 4))));
// { year: 2017, month 6, date: 5, hours: 12, minutes: 0, seconds: 0, milliseconds: 0 }

// We can also retrieve date object. It's important to understand that it won't reflect given time
// point (so should not be used for date timestamp comparisons) but can be used as interim value
// to be used to get formatted date string
console.log(String(shanghaiTokenize(new Date(Date.UTC(2017, 6, 5, 4))).dateObject));
// In CEST Timezone it'll log:
// "Wed Jul 05 2017 12:00:00 GMT+0200 (CEST)"
```

### Installation

    $ npm install date-from-timezone

### Tests

    $ npm test

[build-image]: https://github.com/medikoo/date-from-timezone/workflows/Integrate/badge.svg
[build-url]: https://github.com/medikoo/date-from-timezone/actions?query=workflow%3AIntegrate
[cov-image]: https://img.shields.io/codecov/c/github/medikoo/date-from-timezone.svg
[cov-url]: https://codecov.io/gh/medikoo/date-from-timezone
[npm-image]: https://img.shields.io/npm/v/date-from-timezone.svg
[npm-url]: https://www.npmjs.com/package/date-from-timezone

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