Skip to content

Commit

Permalink
fix: Package both src and dist the in NPM module
Browse files Browse the repository at this point in the history
Support importing ES6 modules in the client code.
  • Loading branch information
prantlf committed Sep 2, 2018
1 parent 6744e79 commit 9b3d588
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Low-level time zone listing and date converting. Intended for adding time zone s

## Synopsis


```js
const {
listTimeZones, findTimeZone, getZonedTime, getUnixTime
Expand Down Expand Up @@ -197,7 +196,7 @@ See the function [parseZonedTime](#parseZonedTime) for more information.
Date pickers usually supply the date, which the user selected and the time zone is implied from user settings. The time zone should be set to such date before it is returned from the editing control.

```js
const { setTimeZone } = require('timezone-support')
const { findTimeZone, setTimeZone } = require('timezone-support')
const berlin = findTimeZone('Europe/Berlin')

// Time object with the date parts without time zone
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
]
},
"files": [
"dist"
"dist",
"src"
],
"jest": {
"roots": [
Expand Down
28 changes: 2 additions & 26 deletions src/convert/convert.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getUnixTimeFromUTC, getUTCTime, getLocalTime } from './utc-date'

function findTransitionIndex (unixTime, timeZone) {
const { untils } = timeZone
for (let i = 0, length = untils.length; i < length; ++i) {
Expand All @@ -14,32 +16,6 @@ function getTransition (unixTime, timeZone) {
return { abbreviation, offset }
}

function getUnixTimeFromUTC ({ year, month, day, hours, minutes, seconds = 0, milliseconds = 0 }) {
return Date.UTC(year, month - 1, day, hours, minutes, seconds, milliseconds)
}

function getUTCTime (date) {
const year = date.getUTCFullYear()
const month = date.getUTCMonth() + 1
const day = date.getUTCDate()
const hours = date.getUTCHours()
const minutes = date.getUTCMinutes()
const seconds = date.getUTCSeconds() || 0
const milliseconds = date.getUTCMilliseconds() || 0
return { year, month, day, hours, minutes, seconds, milliseconds }
}

function getLocalTime (date) {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hours = date.getHours()
const minutes = date.getMinutes()
const seconds = date.getSeconds()
const milliseconds = date.getMilliseconds()
return { year, month, day, hours, minutes, seconds, milliseconds }
}

function setTimeZone (time, timeZone, options) {
if (time instanceof Date) {
const { useUTC } = options || {}
Expand Down
28 changes: 28 additions & 0 deletions src/convert/utc-date.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

function getUnixTimeFromUTC ({ year, month, day, hours, minutes, seconds = 0, milliseconds = 0 }) {
return Date.UTC(year, month - 1, day, hours, minutes, seconds, milliseconds)
}

function getUTCTime (date) {
const year = date.getUTCFullYear()
const month = date.getUTCMonth() + 1
const day = date.getUTCDate()
const hours = date.getUTCHours()
const minutes = date.getUTCMinutes()
const seconds = date.getUTCSeconds() || 0
const milliseconds = date.getUTCMilliseconds() || 0
return { year, month, day, hours, minutes, seconds, milliseconds }
}

function getLocalTime (date) {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hours = date.getHours()
const minutes = date.getMinutes()
const seconds = date.getSeconds()
const milliseconds = date.getMilliseconds()
return { year, month, day, hours, minutes, seconds, milliseconds }
}

export { getUnixTimeFromUTC, getUTCTime, getLocalTime }

0 comments on commit 9b3d588

Please sign in to comment.