Skip to content

Commit

Permalink
feat: Add time zone data module for years 1970-2038
Browse files Browse the repository at this point in the history
  • Loading branch information
prantlf committed Nov 17, 2018
1 parent bc12675 commit 2e5ec2d
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 12 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ dayjs().startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:m
```js
// Load dayjs, plugins and language packs.
import dayjs from 'dayjs-ext'
// import "timeZone-1900-2050" or "timeZone-2012-2022" to save your package size
// import "timeZone-1900-2050", "timeZone-1970-2038"
// or "timeZone-2012-2022" to save your package size
import timeZonePlugin from 'dayjs-ext/plugin/timeZone'
import customParseFormat from 'dayjs-ext/plugin/customParseFormat'
import localizableFormat from 'dayjs-ext/plugin/localizableFormat'
Expand Down Expand Up @@ -97,7 +98,8 @@ console.log(dateOnly.format({ format: 'YYYY-MM-DD' }))
If used in the browser, the following scripts would be needed:

```html
<-- include "index-1900-2050" or "index-2012-2022" to save your package size -->
<-- include "index-1900-2050", "index-1970-2038"
or "index-2012-2022" to save your package size -->
<script arc="https://unpkg.com/timezone-support/dist/index.umd.js"></script>
<script arc="https://unpkg.com/fast-plural-rules/dist/index.umd.js"></script>
<script arc="https://unpkg.com/dayjs-ext/dayjs.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function build(option) {
}))
})

const timeZoneVariants = ['custom', '1900-2050', '2012-2022']
const timeZoneVariants = ['custom', '1900-2050', '1970-2038', '2012-2022']
timeZoneVariants.forEach((moduleName) => {
build(configFactory({
input: `./src/plugin/timeZone/${moduleName}`,
Expand Down
5 changes: 3 additions & 2 deletions build/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = (config) => {
external: [
'dayjs-ext', 'fast-plural-rules', 'timezone-support/dist/lookup-convert',
'timezone-support/dist/data', 'timezone-support/dist/data-1900-2050',
'timezone-support/dist/data-2012-2022'
'timezone-support/dist/data-1970-2038', 'timezone-support/dist/data-2012-2022'
],
plugins: [
babel({
Expand All @@ -25,9 +25,10 @@ module.exports = (config) => {
globals: {
'dayjs-ext': 'dayjs',
'fast-plural-rules': 'fastPluralRules',
'timezone-support/dist/lookup-convert': 'timezone-support',
'timezone-support/dist/lookup-convert': 'timezone-lookup-convert',
'timezone-support/dist/data': 'timezone-data',
'timezone-support/dist/data-1900-2050': 'timezone-data-1900-2050',
'timezone-support/dist/data-1970-2038': 'timezone-data-1970-2038',
'timezone-support/dist/data-2012-2022': 'timezone-data-2012-2022'
},
sourcemap: true
Expand Down
9 changes: 6 additions & 3 deletions docs/en/Plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ If the plugin [LocalizableFormat](#localizableformat) is installed, format token
- TimeZone extends `dayjs()` and `dayjs().format` APIs to support the most important usage scenatrios - parsing from a specific time zone and formatting in other time zone.

```javascript
// import "timeZone-1900-2050" or "timeZone-2012-2022" to save your package size
// import "timeZone-1900-2050", "timeZone-1970-2038"
// or "timeZone-2012-2022" to save your package size
import timeZone from 'dayjs-ext/plugin/timeZone'

dayjs.extend(timeZone)
Expand Down Expand Up @@ -284,10 +285,11 @@ The plugin includes all available time zone data in the main module `dayjs-ext/p
```txt
Full IANA TZ data: 923 KB minified, 33.3 KB gzipped
Data for 1900-2050: 200 KB minified, 23.3 KB gzipped
Data for 1970-2038: 135 KB minified, 13.9 KB gzipped
Data for 2012-2022: 27 KB minified, 6.5 KB gzipped
```

Modules with limited time zone data are exposed as `dayjs-ext/plugin/timeZone-1900-2050` and `dayjs-ext/plugin/timeZone-2012-2022`. A custom module with different time zone data can be used via `dayjs-ext/plugin/timeZone-custom`:
Modules with limited time zone data are exposed as `dayjs-ext/plugin/timeZone-1900-2050`, `dayjs-ext/plugin/timeZone-1970-2038` and `dayjs-ext/plugin/timeZone-2012-2022`. A custom module with different time zone data can be used via `dayjs-ext/plugin/timeZone-custom`:

```js
import dayjs from 'dayjs-ext'
Expand All @@ -308,7 +310,8 @@ When `dayjs-ext` is loaded in the browser as described below, custom data can be
This plugin has a dependency on the [`timezone-support`](https://www.npmjs.com/package/timezone-support) NPM module. If you are going to use it on a web page directly, add its script to your section of `<script>`s too, along with the `Day.js`, for example:

```html
<-- include "index-1900-2050.umd.js" or "index-2012-2022.umd.js" to save your package size -->
<-- include "index-1900-2050.umd.js", "index-1970-2038.umd.js"
or "index-2012-2022.umd.js" to save your package size -->
<script arc="https://unpkg.com/timezone-support/dist/index.umd.js"></script>
<script arc="https://unpkg.com/dayjs-ext/dayjs.min.js"></script>
<script arc="https://unpkg.com/dayjs-ext/plugin/timeZone.js"></script>
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
"plugin/timeZone-custom.js.map",
"plugin/timeZone-1900-2050.js",
"plugin/timeZone-1900-2050.js.map",
"plugin/timeZone-1970-2038.js",
"plugin/timeZone-1970-2038.js.map",
"plugin/timeZone-2012-2022.js",
"plugin/timeZone-2012-2022.js.map",
"plugin/weekOfYear.js",
Expand Down Expand Up @@ -158,7 +160,7 @@
},
"dependencies": {
"fast-plural-rules": "^0.0.1",
"timezone-support": "^1.7.0"
"timezone-support": "^1.8.0"
},
"devDependencies": {
"@babel/cli": "^7.1.5",
Expand Down
6 changes: 6 additions & 0 deletions src/plugin/timeZone/1970-2038.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { populateTimeZones } from 'timezone-support/dist/lookup-convert'
import timeZoneData from 'timezone-support/dist/data-1970-2038'

populateTimeZones(timeZoneData)

export { default } from './custom'

0 comments on commit 2e5ec2d

Please sign in to comment.