Socket
Socket
Sign inDemoInstall

date-fns-timezone

Package Overview
Dependencies
3
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.1.1

8

dist/convertToLocalTime.js

@@ -28,5 +28,7 @@ 'use strict';

* @example
* // Convert the current time to the New York time zone:
* var result = convertToLocalTime(new Date(), { timeZone: 'America/New_York' })
* //=> { date: Date, zone: { abbreviation: 'EST', offset: -300 }
* // Convert the time in the New York time zone to the local time:
* const date = new Date(2018, 8, 2, 10, 0)
* const result = convertToLocalTime(date, { timeZone: 'America/New_York' })
* // Returns { date: Date, zone: { abbreviation: 'EDT', offset: -360 }
* // The date will be "2018-09-02T16:00:00Z".
*/

@@ -33,0 +35,0 @@

@@ -24,9 +24,9 @@ 'use strict';

* @param {Object} options - the object with options
* @param {String} options.timeZone - the canonical name of the source time zone
* @returns {Date} the parsed date in the local time zone
* @param {String} options.timeZone - the canonical name of the target time zone
* @returns {Date} the parsed date in the target time zone
*
* @example
* // Convert the current time to the New York time zone:
* var result = convertToTimeZone(new Date(), { timeZone: 'America/New_York' })
* //=> { date: Date, zone: { abbreviation: 'EST', offset: -300 }
* // Convert the current local time to the New York time zone:
* const result = convertToTimeZone(new Date(), { timeZone: 'America/New_York' })
* Returns { date: Date, zone: { abbreviation: 'EST', offset: -300 }
*/

@@ -33,0 +33,0 @@

@@ -16,11 +16,11 @@ 'use strict';

* @description
* Return the formatted date string in the given format, after converting it, optionally, to the given time zone.
* Returns the formatted date string in the given format, after converting it to the given time zone.
*
* The input date will be converted to the given time zone by default, using its UTC timestamp.
* If the local time in the input date is already in the given time zone, set `options.useLocal` to `true`.
* If the UTC time in the input date is already in the given time zone, set `options.useUTC` to `true`.
* If the local time in the input date is already in the given time zone, set `options.convertTimeZone`
* to `false`. Otherwise the date will be considered in local time and converted.
*
* The time zone has to be specified as a canonical name from the [IANA time zone list]{@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones}.
*
* Accepted tokens:
* The following tokens are recognized in the format string:
*

@@ -94,13 +94,13 @@ * | Unit | Token | Result examples |

* )
* //=> '02/10/2014 7:00 PM GMT-0500 (EST)'
* // Returns '02/10/2014 7:00 PM GMT-0500 (EST)'
*
* @example
* // Represent noon on 2 July 2014 in Esperanto, Madrid time:
* var eoLocale = require('date-fns/locale/eo')
* var locale = require('date-fns/locale/eo')
* var result = formatToTimeZone(
* new Date(2014, 6, 2, 12),
* "HH:mm, do 'de' MMMM yyyy (Zz)",
* { locale: eo, timeZone: 'Europe/Madrid', convertTimeZone: false }
* { locale, timeZone: 'Europe/Madrid', convertTimeZone: false }
* )
* //=> '12:00, 2-a de julio 2014 (+02:00 CEST)'
* // Returns '12:00, 2-a de julio 2014 (+02:00 CEST)'
*/

@@ -107,0 +107,0 @@

@@ -31,5 +31,7 @@ 'use strict';

* @example
* // Convert the current time to the New York time zone:
* var result = convertToLocalTime(new Date(), { timeZone: 'America/New_York' })
* //=> { date: Date, zone: { abbreviation: 'EST', offset: -300 }
* // Convert the time in the New York time zone to the local time:
* const date = new Date(2018, 8, 2, 10, 0)
* const result = convertToLocalTime(date, { timeZone: 'America/New_York' })
* // Returns { date: Date, zone: { abbreviation: 'EDT', offset: -360 }
* // The date will be "2018-09-02T16:00:00Z".
*/

@@ -62,9 +64,9 @@

* @param {Object} options - the object with options
* @param {String} options.timeZone - the canonical name of the source time zone
* @returns {Date} the parsed date in the local time zone
* @param {String} options.timeZone - the canonical name of the target time zone
* @returns {Date} the parsed date in the target time zone
*
* @example
* // Convert the current time to the New York time zone:
* var result = convertToTimeZone(new Date(), { timeZone: 'America/New_York' })
* //=> { date: Date, zone: { abbreviation: 'EST', offset: -300 }
* // Convert the current local time to the New York time zone:
* const result = convertToTimeZone(new Date(), { timeZone: 'America/New_York' })
* Returns { date: Date, zone: { abbreviation: 'EST', offset: -300 }
*/

@@ -89,5 +91,5 @@

* @description
* Return the date parsed from the date string, using the given format string, and convert the parsed date to the local time.
* Returns the date parsed from the date string using the given format string and converts the parsed date to the local time.
*
* The following tokens will be recognized in the format string then:
* The following tokens are recognized in the format string:
*

@@ -121,5 +123,3 @@ * | Token | Input example | Description |

*
* The time zone has to be specified as a canonical name from the [IANA time zone list]{@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones}.
*
* @param {String} dateString - the value to convert
* @param {String} dateString - the string to parse
* @param {String} formatString - the custom format to parse the date from

@@ -130,9 +130,10 @@ * @returns {Date} the parsed date in the local time zone

* // Parse string '11.2.2014 11:30:30' to date in Berlin:
* var result = parseFromTimeZone('11.2.2014 11:30:30', 'D.M.YYYY H:mm:ss')
* //=> Tue Feb 11 2014 10:30:30 UTC
* const result = parseFromTimeZone('11.2.2014 11:30:30', 'D.M.YYYY H:mm:ss')
* // Returns Tue Feb 11 2014 10:30:30 UTC
*
* @example
* // Parse string '02/11/2014 11:30:30' to date, New York time:
* var result = parseFromString('02/11/2014 11:30:30 AM GMT-0500 (EDT)',
* const result = parseFromString('02/11/2014 11:30:30 AM GMT-0500 (EDT)',
* 'MM/DD/YYYY h:mm:ss.SSS A [GMT]ZZ (z)')
* //=> Tue Feb 11 2014 16:30:30 UTC
* // Returns Tue Feb 11 2014 16:30:30 UTC
*/

@@ -151,7 +152,7 @@

* @description
* Return the date parsed from the date string, optionally using the given format string, and convert the parsed date from the given time zone to the local time.
* Returns the date parsed from the date string, optionally using the given format string, and convert the parsed date from the given time zone to the local time.
*
* If the format string is omitted, the date string will be parsed by `date-fns/parse`, which supports extended ISO 8601 formats.
*
* The following tokens will be recognized in the format string then:
* The following tokens are recognized in the format string:
*

@@ -187,3 +188,3 @@ * | Token | Input example | Description |

*
* @param {String} dateString - the value to convert
* @param {String} dateString - the string to parse
* @param {String} [formatString] - the custom format to parse the date from

@@ -197,11 +198,11 @@ * @param {Object} options - the object with options

* // Parse string '2014-02-11 11:30:30 AM' to date, New York time:
* var result = parseFromTimeZone('2014-02-11 11:30:30',
* const result = parseFromTimeZone('2014-02-11 11:30:30',
* { timeZone: 'America/New_York' })
* //=> Tue Feb 11 2014 16:30:30 UTC
* // Returns Tue Feb 11 2014 16:30:30 UTC
*
* @example
* // Parse string '11.2.2014 11:30:30' to date, Berlin time:
* var result = parseFromTimeZone('11.2.2014 11:30:30',
* const result = parseFromTimeZone('11.2.2014 11:30:30',
* 'D.M.YYYY H:mm:ss', { timeZone: 'Europe/Berlin' })
* //=> Tue Feb 11 2014 10:30:30 UTC
* // Returns Tue Feb 11 2014 10:30:30 UTC
*

@@ -247,11 +248,11 @@ * @example

* @description
* Return the formatted date string in the given format, after converting it, optionally, to the given time zone.
* Returns the formatted date string in the given format, after converting it to the given time zone.
*
* The input date will be converted to the given time zone by default, using its UTC timestamp.
* If the local time in the input date is already in the given time zone, set `options.useLocal` to `true`.
* If the UTC time in the input date is already in the given time zone, set `options.useUTC` to `true`.
* If the local time in the input date is already in the given time zone, set `options.convertTimeZone`
* to `false`. Otherwise the date will be considered in local time and converted.
*
* The time zone has to be specified as a canonical name from the [IANA time zone list]{@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones}.
*
* Accepted tokens:
* The following tokens are recognized in the format string:
*

@@ -325,13 +326,13 @@ * | Unit | Token | Result examples |

* )
* //=> '02/10/2014 7:00 PM GMT-0500 (EST)'
* // Returns '02/10/2014 7:00 PM GMT-0500 (EST)'
*
* @example
* // Represent noon on 2 July 2014 in Esperanto, Madrid time:
* var eoLocale = require('date-fns/locale/eo')
* var locale = require('date-fns/locale/eo')
* var result = formatToTimeZone(
* new Date(2014, 6, 2, 12),
* "HH:mm, do 'de' MMMM yyyy (Zz)",
* { locale: eo, timeZone: 'Europe/Madrid', convertTimeZone: false }
* { locale, timeZone: 'Europe/Madrid', convertTimeZone: false }
* )
* //=> '12:00, 2-a de julio 2014 (+02:00 CEST)'
* // Returns '12:00, 2-a de julio 2014 (+02:00 CEST)'
*/

@@ -338,0 +339,0 @@

@@ -14,5 +14,5 @@ 'use strict';

* @description
* Return the date parsed from the date string, using the given format string, and convert the parsed date to the local time.
* Returns the date parsed from the date string using the given format string and converts the parsed date to the local time.
*
* The following tokens will be recognized in the format string then:
* The following tokens are recognized in the format string:
*

@@ -46,5 +46,3 @@ * | Token | Input example | Description |

*
* The time zone has to be specified as a canonical name from the [IANA time zone list]{@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones}.
*
* @param {String} dateString - the value to convert
* @param {String} dateString - the string to parse
* @param {String} formatString - the custom format to parse the date from

@@ -55,9 +53,10 @@ * @returns {Date} the parsed date in the local time zone

* // Parse string '11.2.2014 11:30:30' to date in Berlin:
* var result = parseFromTimeZone('11.2.2014 11:30:30', 'D.M.YYYY H:mm:ss')
* //=> Tue Feb 11 2014 10:30:30 UTC
* const result = parseFromTimeZone('11.2.2014 11:30:30', 'D.M.YYYY H:mm:ss')
* // Returns Tue Feb 11 2014 10:30:30 UTC
*
* @example
* // Parse string '02/11/2014 11:30:30' to date, New York time:
* var result = parseFromString('02/11/2014 11:30:30 AM GMT-0500 (EDT)',
* const result = parseFromString('02/11/2014 11:30:30 AM GMT-0500 (EDT)',
* 'MM/DD/YYYY h:mm:ss.SSS A [GMT]ZZ (z)')
* //=> Tue Feb 11 2014 16:30:30 UTC
* // Returns Tue Feb 11 2014 16:30:30 UTC
*/

@@ -64,0 +63,0 @@

@@ -17,7 +17,7 @@ 'use strict';

* @description
* Return the date parsed from the date string, optionally using the given format string, and convert the parsed date from the given time zone to the local time.
* Returns the date parsed from the date string, optionally using the given format string, and convert the parsed date from the given time zone to the local time.
*
* If the format string is omitted, the date string will be parsed by `date-fns/parse`, which supports extended ISO 8601 formats.
*
* The following tokens will be recognized in the format string then:
* The following tokens are recognized in the format string:
*

@@ -53,3 +53,3 @@ * | Token | Input example | Description |

*
* @param {String} dateString - the value to convert
* @param {String} dateString - the string to parse
* @param {String} [formatString] - the custom format to parse the date from

@@ -63,11 +63,11 @@ * @param {Object} options - the object with options

* // Parse string '2014-02-11 11:30:30 AM' to date, New York time:
* var result = parseFromTimeZone('2014-02-11 11:30:30',
* const result = parseFromTimeZone('2014-02-11 11:30:30',
* { timeZone: 'America/New_York' })
* //=> Tue Feb 11 2014 16:30:30 UTC
* // Returns Tue Feb 11 2014 16:30:30 UTC
*
* @example
* // Parse string '11.2.2014 11:30:30' to date, Berlin time:
* var result = parseFromTimeZone('11.2.2014 11:30:30',
* const result = parseFromTimeZone('11.2.2014 11:30:30',
* 'D.M.YYYY H:mm:ss', { timeZone: 'Europe/Berlin' })
* //=> Tue Feb 11 2014 10:30:30 UTC
* // Returns Tue Feb 11 2014 10:30:30 UTC
*

@@ -74,0 +74,0 @@ * @example

{
"name": "date-fns-timezone",
"version": "0.1.0",
"version": "0.1.1",
"description": "Parsing and formatting date strings using IANA time zones for date-fns.",

@@ -76,3 +76,3 @@ "author": {

"date-fns": "^1.29.0",
"timezone-support": "^1.3.1"
"timezone-support": "^1.3.2"
},

@@ -101,10 +101,10 @@ "devDependencies": {

"rimraf": "^2.6.2",
"rollup": "^0.66.0",
"rollup": "^0.66.2",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-uglify": "^6.0.0",
"semantic-release": "^15.9.15",
"semantic-release": "^15.9.16",
"serve-static": "^1.13.2",
"standard": "^12.0.1",
"tiny-glob": "^0.2.2",
"travis-deploy-once": "^5.0.7"
"travis-deploy-once": "^5.0.8"
},

@@ -111,0 +111,0 @@ "keywords": [

@@ -6,3 +6,2 @@ # date-fns-timezone

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4bb0f2ef6c1b4212a4ed2dbf1f3e8b29)](https://www.codacy.com/app/prantlf/date-fns-timezone?utm_source=github.com&utm_medium=referral&utm_content=prantlf/date-fns-timezone&utm_campaign=Badge_Grade)
utm_content=prantlf/date-fns-timezone&utm_campaign=Badge_Grade)
[![Dependency Status](https://david-dm.org/prantlf/date-fns-timezone.svg)](https://david-dm.org/prantlf/date-fns-timezone)

@@ -14,11 +13,8 @@ [![devDependency Status](https://david-dm.org/prantlf/date-fns-timezone/dev-status.svg)](https://david-dm.org/prantlf/date-fns-timezone#info=devDependencies)

### Table of Contents
- [Synopsis](#synopsis)
- [Installation and Loading](#installation-and-loading)
- [Specific Environments](#specific-environments)
- [Usage Scenarios](#usage-scenarios)
- [List all available time zones](#list-all-available-time-zones)
- [Parse a date from a string in a specific time zone](#parse-a-date-from-a-string-in-a-specific-time-zone)
- [Format a date to a string in specific time zone](#format-a-date-to-a-string-in-specific-time-zone)
- [Change the time zone of date](#change-the-time-zone-of-date)
- [API Reference](#api-reference)
- [Installation and Getting Started](#installation-and-getting-started)
- [Usage Scenarios](./docs/usage.md#usage-scenarios)
- [API Reference](./docs/API.md#api-reference)
- [Contributing](#contributing)

@@ -46,3 +42,3 @@ - [Release History](#release-history)

## Installation and Loading
## Installation and Getting Started

@@ -59,161 +55,10 @@ This module can be installed in your project using [NPM] or [Yarn]. Make sure, that you use [Node.js] version 6 or newer.

### Specific Environments
Functions are exposed as named exports from the package modules, for example:
Load the main module in an application using CommonJS modules:
```js
const {
convertToLocalTime, convertToTimeZone, parseFromTimeZone, formatToTimeZone
} = require('date-fns-timezone')
const { parseFromTimeZone, formatToTimeZone } = require('date-fns-timezone')
```
Load only specific modules in an application using CommonJS modules:
You can read more about the [module loading](./docs/API.md#loading) in other environments, like with ES6 or in web browsers. [Usage scenarios](./docs/usage.md#usage-scenarios) demonstrate applications of this library in typical real-world scenarios. The [API reference](./docs/API.md#api-reference) lists all functions with a description of their functionality.
```js
const { convertToLocalTime } = require('date-fns-timezone/dist/convertToLocalTime')
const { convertToTimeZone } = require('date-fns-timezone/dist/convertToTimeZone')
const { parseFromTimeZone } = require('date-fns-timezone/dist/parseFromTimeZone')
const { formatToTimeZone } = require('date-fns-timezone/dist/formatToTimeZone')
```
Load the main module in an application using ES6 modules:
```js
import {
convertToLocalTime, convertToTimeZone, parseFromTimeZone, formatToTimeZone
} from './node_modules/date-fns-timezone/src/index.js'
```
Load only specific modules in an application using ES6 modules:
```js
import { convertToLocalTime } from './node_modules/date-fns-timezone/src/convertToLocalTime.js'
import { convertToTimeZone } from './node_modules/date-fns-timezone/src/convertToTimeZone.js'
import { parseFromTimeZone } from './node_modules/date-fns-timezone/src/parseFromTimeZone.js'
import { formatToTimeZone } from './node_modules/date-fns-timezone/src/formatToTimeZone.js'
```
Load the main module in the browser with plain JavaScript:
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/date-fns/1.29.0/date_fns.min.js"></script>
<script src="https://unpkg.com/timezone-support@1.2.1/dist/index.umd.js"></script>
<script src="https://unpkg.com/date-fns-timezone@0.0.1/dist/index.umd.js"></script>
<script>
(() => {
const {
convertToLocalTime, convertToTimeZone, parseFromTimeZone, formatToTimeZone
} = window.dateFnsTimezone
})()
</script>
```
Load the main module in the browser with [RequireJS]:
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/date-fns/1.29.0/date_fns.min.js"></script>
<script src="https://unpkg.com/timezone-support@1.2.1/dist/index.umd.js"></script>
<script src="https://unpkg.com/date-fns-timezone@0.0.1/dist/index.umd.js"></script>
<script>
require(['date-fns-timezone'], ({ parseFromTimeZone, formatToTimeZone }) => {
})
</script>
```
## Usage Scenarios
The minimal, but powerful API of this module provides functionality for the most usual usage scenarios in your web applications.
### List all available time zones
Users may need to choose the time zone, which they want to see and enter dates in. Time zones can be listed in a dropdown for the user to choose from, for example.
```js
const { listTimeZones } = require('timezone-support')
const timeZones = listTimeZones()
```
See the function [listTimeZones] for more information.
### Parse a date from a string in a specific time zone
Dates are usually entered in a time zone chosen by the user, but they are supposed to be stored in UTC. After the user input is parsed, the result date needs to be converted from the user time zone to the native `Date` object, which maintains the date in the browser-local time zone and UTC.
```js
const { parseZonedTime } = require('date-fns-timezone/dist/parseFromTimeZone')
const enteredTime = '2018-09-02 12:04:30.982'
const timeZone = 'Europe/Berlin'
const storedDate = parseFromTimeZone(enteredTime, { timeZone })
// Contains date "2018-09-02T10:04:30.982Z"
const enteredTime = '09/02/2018 12:04:30.982 PM'
const customFormat = 'MM/DD/YYYY h:mm:ss.SSS A'
const timeZone = 'America/New_York'
const storedDate = parseFromTimeZone(enteredTime, { timeZone })
// Contains date "2018-09-02T18:04:30.982Z"
```
See the function [parseFromTimeZone](#parsefromtimezone) for more information.
### Format a date to a string in specific time zone
Dates are supposed to be stored in UTC, but they are usually displayed in a time zone chosen by the user. Before the date value is formatted, it needs to be converted to the user time zone.
```js
const { formatToTimeZone } = require('date-fns-timezone/dist/formatToTimeZone')
const storedDate = new Date('2018-09-02T10:04:30.982Z')
const format = 'D.M.YYYY H:mm:ss [GMT]Z (z)'
const timeZone = 'Europe/Berlin'
const displayedTime = formatToTimeZone(storedDate, format, { timeZone })
// Contains string "2.9.2018 12:04:30 GMT+02:00 (CEST)"
```
See the function [formatToTimeZone](#formattotimezone) for more information.
### Change the time zone of date
Date pickers usually supply the date, which the user selected, and the time zone is implied from the user settings. The local time in the date value is not the browser-local time and the UTC value cannot be used yet. The date has to be converted from the user time zone to the browser-local time to become valid.
```js
const { convertToLocalTime } = require('date-fns-timezone/dist/convertToLocalTime')
const chosenDate = new Date(2018, 8, 2, 12, 4, 30, 982)
const timeZone = 'Europe/Berlin'
const storedDate = convertToLocalTime(chosenDate, { timeZone })
// Contains date "2018-09-02T10:04:30.982Z"
```
Date pickers are usually initialized by a date in the time zone implied from the user settings. However, the browser-local time may be different. The date has to be converted from the browser-local time to the user time zone.
```js
const { convertToTimeZone } = require('date-fns-timezone/dist/convertToTimeZone')
const storedDate = new Date('2018-09-02T10:04:30.982Z')
const timeZone = 'Europe/Berlin'
const defaultDate = convertToTimeZone(storedDate, { timeZone })
// Contains date "2018-09-02 12:04:30.982"
```
See functions [convertToLocalTime](#converttolocaltime) and [convertToTimeZone](#converttotimezone) for more information.
## API Reference
The API consists of functions only. They are divided to three modules, which you can load separately or together depending on your usage scenario.
### date-fns-timezone/dist/index
Main package module for Node.js application. CommonJS format. Includes all functions from the other modules.
### date-fns-timezone/dist/index.umd.js
Main package module first of all for web browsers. UMD format, minified. Includes all functions from the other modules. Make sure, that you include `script` elements for `date-fns` and `timezone-support` on your web page before this one [as documented earlier](#specific-environments).
### convertToLocalTime
### convertToTimeZone
### parseFromTimeZone
### formatToTimeZone
## Contributing

@@ -225,2 +70,3 @@

* 2018-09-19 v0.1.0 Add parseString without a time zone to cover a gap in date-fns
* 2018-09-17 v0.0.1 Initial release

@@ -241,2 +87,1 @@

[RequireJS]: https://requirejs.org/
[listTimeZones]: https://github.com/prantlf/timezone-support#listtimezones

@@ -23,5 +23,7 @@ /** @module date-fns */

* @example
* // Convert the current time to the New York time zone:
* var result = convertToLocalTime(new Date(), { timeZone: 'America/New_York' })
* //=> { date: Date, zone: { abbreviation: 'EST', offset: -300 }
* // Convert the time in the New York time zone to the local time:
* const date = new Date(2018, 8, 2, 10, 0)
* const result = convertToLocalTime(date, { timeZone: 'America/New_York' })
* // Returns { date: Date, zone: { abbreviation: 'EDT', offset: -360 }
* // The date will be "2018-09-02T16:00:00Z".
*/

@@ -28,0 +30,0 @@ function convertToLocalTime (argument, options) {

@@ -19,9 +19,9 @@ /** @module date-fns */

* @param {Object} options - the object with options
* @param {String} options.timeZone - the canonical name of the source time zone
* @returns {Date} the parsed date in the local time zone
* @param {String} options.timeZone - the canonical name of the target time zone
* @returns {Date} the parsed date in the target time zone
*
* @example
* // Convert the current time to the New York time zone:
* var result = convertToTimeZone(new Date(), { timeZone: 'America/New_York' })
* //=> { date: Date, zone: { abbreviation: 'EST', offset: -300 }
* // Convert the current local time to the New York time zone:
* const result = convertToTimeZone(new Date(), { timeZone: 'America/New_York' })
* Returns { date: Date, zone: { abbreviation: 'EST', offset: -300 }
*/

@@ -28,0 +28,0 @@ function convertToTimeZone (argument, options) {

@@ -11,11 +11,11 @@ /** @module date-fns */

* @description
* Return the formatted date string in the given format, after converting it, optionally, to the given time zone.
* Returns the formatted date string in the given format, after converting it to the given time zone.
*
* The input date will be converted to the given time zone by default, using its UTC timestamp.
* If the local time in the input date is already in the given time zone, set `options.useLocal` to `true`.
* If the UTC time in the input date is already in the given time zone, set `options.useUTC` to `true`.
* If the local time in the input date is already in the given time zone, set `options.convertTimeZone`
* to `false`. Otherwise the date will be considered in local time and converted.
*
* The time zone has to be specified as a canonical name from the [IANA time zone list]{@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones}.
*
* Accepted tokens:
* The following tokens are recognized in the format string:
*

@@ -89,13 +89,13 @@ * | Unit | Token | Result examples |

* )
* //=> '02/10/2014 7:00 PM GMT-0500 (EST)'
* // Returns '02/10/2014 7:00 PM GMT-0500 (EST)'
*
* @example
* // Represent noon on 2 July 2014 in Esperanto, Madrid time:
* var eoLocale = require('date-fns/locale/eo')
* var locale = require('date-fns/locale/eo')
* var result = formatToTimeZone(
* new Date(2014, 6, 2, 12),
* "HH:mm, do 'de' MMMM yyyy (Zz)",
* { locale: eo, timeZone: 'Europe/Madrid', convertTimeZone: false }
* { locale, timeZone: 'Europe/Madrid', convertTimeZone: false }
* )
* //=> '12:00, 2-a de julio 2014 (+02:00 CEST)'
* // Returns '12:00, 2-a de julio 2014 (+02:00 CEST)'
*/

@@ -102,0 +102,0 @@ function formatToTimeZone (date, formatString, options) {

@@ -11,5 +11,5 @@ /** @module date-fns */

* @description
* Return the date parsed from the date string, using the given format string, and convert the parsed date to the local time.
* Returns the date parsed from the date string using the given format string and converts the parsed date to the local time.
*
* The following tokens will be recognized in the format string then:
* The following tokens are recognized in the format string:
*

@@ -43,5 +43,3 @@ * | Token | Input example | Description |

*
* The time zone has to be specified as a canonical name from the [IANA time zone list]{@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones}.
*
* @param {String} dateString - the value to convert
* @param {String} dateString - the string to parse
* @param {String} formatString - the custom format to parse the date from

@@ -52,9 +50,10 @@ * @returns {Date} the parsed date in the local time zone

* // Parse string '11.2.2014 11:30:30' to date in Berlin:
* var result = parseFromTimeZone('11.2.2014 11:30:30', 'D.M.YYYY H:mm:ss')
* //=> Tue Feb 11 2014 10:30:30 UTC
* const result = parseFromTimeZone('11.2.2014 11:30:30', 'D.M.YYYY H:mm:ss')
* // Returns Tue Feb 11 2014 10:30:30 UTC
*
* @example
* // Parse string '02/11/2014 11:30:30' to date, New York time:
* var result = parseFromString('02/11/2014 11:30:30 AM GMT-0500 (EDT)',
* const result = parseFromString('02/11/2014 11:30:30 AM GMT-0500 (EDT)',
* 'MM/DD/YYYY h:mm:ss.SSS A [GMT]ZZ (z)')
* //=> Tue Feb 11 2014 16:30:30 UTC
* // Returns Tue Feb 11 2014 16:30:30 UTC
*/

@@ -61,0 +60,0 @@ function parseFromString (dateString, formatString) {

@@ -12,7 +12,7 @@ /** @module date-fns */

* @description
* Return the date parsed from the date string, optionally using the given format string, and convert the parsed date from the given time zone to the local time.
* Returns the date parsed from the date string, optionally using the given format string, and convert the parsed date from the given time zone to the local time.
*
* If the format string is omitted, the date string will be parsed by `date-fns/parse`, which supports extended ISO 8601 formats.
*
* The following tokens will be recognized in the format string then:
* The following tokens are recognized in the format string:
*

@@ -48,3 +48,3 @@ * | Token | Input example | Description |

*
* @param {String} dateString - the value to convert
* @param {String} dateString - the string to parse
* @param {String} [formatString] - the custom format to parse the date from

@@ -58,11 +58,11 @@ * @param {Object} options - the object with options

* // Parse string '2014-02-11 11:30:30 AM' to date, New York time:
* var result = parseFromTimeZone('2014-02-11 11:30:30',
* const result = parseFromTimeZone('2014-02-11 11:30:30',
* { timeZone: 'America/New_York' })
* //=> Tue Feb 11 2014 16:30:30 UTC
* // Returns Tue Feb 11 2014 16:30:30 UTC
*
* @example
* // Parse string '11.2.2014 11:30:30' to date, Berlin time:
* var result = parseFromTimeZone('11.2.2014 11:30:30',
* const result = parseFromTimeZone('11.2.2014 11:30:30',
* 'D.M.YYYY H:mm:ss', { timeZone: 'Europe/Berlin' })
* //=> Tue Feb 11 2014 10:30:30 UTC
* // Returns Tue Feb 11 2014 10:30:30 UTC
*

@@ -69,0 +69,0 @@ * @example

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc