Comparing version 0.0.2 to 0.0.3
@@ -8,6 +8,3 @@ var nthOfMonth = require('../util/nth-of-month'); | ||
console.log(new Date(dstStart).toISOString()); | ||
console.log(new Date(dstEnd).toISOString()); | ||
return date >= dstStart && date < dstEnd; | ||
}; |
{ | ||
"name": "easy-tz", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
151
README.md
@@ -92,3 +92,3 @@ # Easy TZ | ||
tz.from({ | ||
date: '2016-01-01',this.get('startDate'), | ||
date: '2016-01-01', | ||
time: '11:00' | ||
@@ -104,3 +104,7 @@ }); | ||
function printDate(date) { | ||
function twoDigits(val) { | ||
return val >= 10 ? val : '0' + val; | ||
} | ||
function printLong(date) { | ||
return [ | ||
@@ -111,12 +115,25 @@ locale.days[date.getDay()].slice(0,3), | ||
date.getFullYear(), | ||
[ date.getHours(), | ||
date.getMinutes() | ||
].map(twoDigits).join(':'), | ||
[ date.getHours(), date.getMinutes() ].map(twoDigits).join(':'), | ||
date.tz && date.tz[1] | ||
]).join(' '); | ||
].join(' '); | ||
} | ||
printDate(tz.to('2016-01-01T12:00:00')); | ||
function printShort(date) { | ||
var dateStr = [ | ||
date.getFullYear(), | ||
date.getMonth() + 1, | ||
date.getDate() | ||
].map(twoDigits).join('-'); | ||
tz.to('2016-01-01T12:00:00').toLocaleString('sv'); | ||
var timeStr = [ date.getHours(), date.getMinutes() ].map(twoDigits).join(':'); | ||
return dateStr + ' ' + timeStr; | ||
} | ||
printLong(tzStockholm.to('2016-01-31T12:00:00.000Z'));// sön 31 januari 2016 13:00 CET | ||
printShort(tzStockholm.to('2016-01-31T12:00:00.000Z'));// 2016-01301 13:00 | ||
tzStockholm.to('2016-01-31T12:00:00.000Z').toLocaleString('sv');// 2016-01-31 13:00:00 | ||
tzStockholm.to('2016-01-31T12:00:00.000Z').toLocaleString('en-GB');// 31/01/2016, 13:00:00 | ||
tzStockholm.to('2016-01-31T12:00:00.000Z').toLocaleString('en-US');// 1/31/2016, 1:00:00 PM | ||
``` | ||
@@ -126,3 +143,4 @@ | ||
Easy TZ provides a `nthOfMonth` helper to assist in creating your own timezones. | ||
Easy TZ provides a `nthOfMonth` helper to assist in creating your own | ||
timezones. | ||
@@ -148,4 +166,4 @@ ```js | ||
var year = date.getUTCFullYear(), | ||
dstStart = Date.UTC(year, 2, nthOfMonth(year, 2, 0, -1), 1), | ||
dstEnd = Date.UTC(year, 9, nthOfMonth(year, 9, 0, -1), 1); | ||
dstStart = Date.UTC(year, 2, nthOfMonth(year, 2, 0, -1), 1),// last sunday in march at 01:00 UTC | ||
dstEnd = Date.UTC(year, 9, nthOfMonth(year, 9, 0, -1), 1);// last sunday in october at 01:00 UTC | ||
@@ -156,18 +174,32 @@ return date >= dstStart && date < dstEnd; | ||
The timezone for CET (./zoneinfo/CET.js) looks like this: | ||
For example, `easy-tz/dst/usa` looks like this: | ||
```js | ||
module.exports = { | ||
dst: require('../dst/europe'), | ||
saving: [ 'CEST', 'GMT+2', 120 ], | ||
standard: [ 'CET', 'GMT+1', 60 ] | ||
var nthOfMonth = require('../util/nth-of-month'); | ||
module.exports = function(date, timezone) { | ||
var year = date.getUTCFullYear(), | ||
dstStart = Date.UTC(year, 2, nthOfMonth(year, 2, 0, 2), 2, timezone.standard[0]),// starts second sunday in march at 2 am local time (2am > 3am, "spring forward") | ||
dstEnd = Date.UTC(year, 9, nthOfMonth(year, 10, 0, 1), 2, timezone.saving[0]);// ends first sunday in november at 2 am local time (2am > 1am, "fall back") | ||
return date >= dstStart && date < dstEnd; | ||
}; | ||
``` | ||
Which is then used in a file, eg ('./zoneinfo/Europe/Stockholm') like so | ||
The timezone for CET (./zoneinfo/CET.js) looks like this: | ||
```js | ||
module.exports = require('../CET'); | ||
module.exports = [ 60, 'CET', 'GMT+1', 'UTC+1' ]; | ||
``` | ||
Which is then used in a file, eg ('./zoneinfo/Europe/Stockholm') like so: | ||
```js | ||
module.exports = { | ||
dst: require('../../dst/europe'), | ||
saving: require('../CEST'), | ||
standard: require('../CET') | ||
}; | ||
``` | ||
If your timezone does not use Daylight Saving Time, simply return an array. | ||
@@ -177,3 +209,3 @@ The timezone for America/La_Paz looks like this. | ||
```js | ||
module.exports = [ 'BOT', 'GMT-4', -240 ]; | ||
module.exports = [ -240, 'BOT', 'GMT-4', 'UTC-4' ]; | ||
``` | ||
@@ -185,15 +217,18 @@ | ||
- ./zoneinfo/ACST | ||
- ./zoneinfo/AEDT | ||
- ./zoneinfo/AEST | ||
- ./zoneinfo/AWST | ||
- ./zoneinfo/CEST (Central Europe Summer Time, not in `/usr/share/zoneinfo`) | ||
- ./zoneinfo/ACST (Australian Central Standard Time, not in `/usr/share/zoneinfo/`) | ||
- ./zoneinfo/AEDT (Australian Eastern Dayling Time, not in `/usr/share/zoneinfo/`) | ||
- ./zoneinfo/AEST (Australian Eastern Standard Time, not in `/usr/share/zoneinfo/`) | ||
- ./zoneinfo/AWST (Australian Western Standard Time, not in `/usr/share/zoneinfo/`) | ||
- ./zoneinfo/CEST (Central Europe Summer Time, not in `/usr/share/zoneinfo/`) | ||
- ./zoneinfo/CET | ||
- ./zoneinfo/EAT (Eastern African Time, not in `/usr/share/zoneinfo/`) | ||
- ./zoneinfo/EEST (Eastern Europe Summer Time, not in `/usr/share/zoneinfo`) | ||
- ./zoneinfo/EEST (Eastern Europe Summer Time, not in `/usr/share/zoneinfo/`) | ||
- ./zoneinfo/EET | ||
- ./zoneinfo/EET | ||
- ./zoneinfo/FET (Further-eastern Europe Time, not in `/usr/share/zoneinfo/`) | ||
- ./zoneinfo/GB | ||
- ./zoneinfo/GB | ||
- ./zoneinfo/GMT | ||
- ./zoneinfo/IST (Moscow Time, not in `/usr/share/zoneinfo/`) | ||
- ./zoneinfo/MSK (Moscow Time, not in `/usr/share/zoneinfo/`) | ||
- ./zoneinfo/US | ||
@@ -203,3 +238,3 @@ - ./zoneinfo/UTC | ||
- ./zoneinfo/WAT | ||
- ./zoneinfo/WEST (Western Europe Summer Time, not in `/usr/share/zoneinfo`) | ||
- ./zoneinfo/WEST (Western Europe Summer Time, not in `/usr/share/zoneinfo/`) | ||
- ./zoneinfo/WET | ||
@@ -239,18 +274,68 @@ - ./zoneinfo/Africa/Addis_Adaba | ||
- ./zoneinfo/Australia/Sydney | ||
- ./zoneinfo/US/Alaska | ||
- ./zoneinfo/US/Aleutian | ||
- ./zoneinfo/US/Central | ||
- ./zoneinfo/US/Eastern | ||
- ./zoneinfo/US/Hawaii | ||
- ./zoneinfo/US/Mountain | ||
- ./zoneinfo/US/Pactific | ||
- ./zoneinfo/Europe/Amsterdam | ||
- ./zoneinfo/Europe/Andorra | ||
- ./zoneinfo/Europe/Athens | ||
- ./zoneinfo/Europe/Barcelona | ||
- ./zoneinfo/Europe/Belfast | ||
- ./zoneinfo/Europe/Belgrade | ||
- ./zoneinfo/Europe/Berlin | ||
- ./zoneinfo/Europe/Bratislava | ||
- ./zoneinfo/Europe/Brussels | ||
- ./zoneinfo/Europe/Bucharest | ||
- ./zoneinfo/Europe/Budapest | ||
- ./zoneinfo/Europe/Busingen | ||
- ./zoneinfo/Europe/Chisinau | ||
- ./zoneinfo/Europe/Copenhagen | ||
- ./zoneinfo/Europe/Dublin | ||
- ./zoneinfo/Europe/Gibraltar | ||
- ./zoneinfo/Europe/Guernsey | ||
- ./zoneinfo/Europe/Helsinki | ||
- ./zoneinfo/Europe/Isle_of_Man | ||
- ./zoneinfo/Europe/Istanbul | ||
- ./zoneinfo/Europe/Jersey | ||
- ./zoneinfo/Europe/Kaliningrad | ||
- ./zoneinfo/Europe/Kiev | ||
- ./zoneinfo/Europe/Lisbon | ||
- ./zoneinfo/Europe/Ljubljana | ||
- ./zoneinfo/Europe/London | ||
- ./zoneinfo/Europe/Luxembourg | ||
- ./zoneinfo/Europe/Madrid | ||
- ./zoneinfo/Europe/Malta | ||
- ./zoneinfo/Europe/Mariehamn | ||
- ./zoneinfo/Europe/Minsk | ||
- ./zoneinfo/Europe/Monaco | ||
- ./zoneinfo/Europe/Moscow | ||
- ./zoneinfo/Europe/Nicosia | ||
- ./zoneinfo/Europe/Oslo | ||
- ./zoneinfo/Europe/Paris | ||
- ./zoneinfo/Europe/Podgorica | ||
- ./zoneinfo/Europe/Prague | ||
- ./zoneinfo/Europe/Riga | ||
- ./zoneinfo/Europe/Rome | ||
- ./zoneinfo/Europe/Samara | ||
- ./zoneinfo/Europe/San_Morino | ||
- ./zoneinfo/Europe/Sarajevo | ||
- ./zoneinfo/Europe/Simferopol | ||
- ./zoneinfo/Europe/Skopje | ||
- ./zoneinfo/Europe/Sofia | ||
- ./zoneinfo/Europe/Stockholm | ||
- ./zoneinfo/Europe/Tallinn | ||
- ./zoneinfo/Europe/Tirane | ||
- ./zoneinfo/Europe/Tiraspol | ||
- ./zoneinfo/Europe/Uzhgorod | ||
- ./zoneinfo/Europe/Vaduz | ||
- ./zoneinfo/Europe/Vatican | ||
- ./zoneinfo/Europe/Vienna | ||
- ./zoneinfo/Europe/Vilnius | ||
- ./zoneinfo/Europe/Volgograd | ||
- ./zoneinfo/Europe/Warsaw | ||
- ./zoneinfo/Europe/Zagreb | ||
- ./zoneinfo/Europe/Zaporozhye | ||
- ./zoneinfo/Europe/Zurich | ||
- ./zoneinfo/US/Alaska | ||
- ./zoneinfo/US/Aleutian | ||
- ./zoneinfo/US/Central | ||
- ./zoneinfo/US/Eastern | ||
- ./zoneinfo/US/Hawaii | ||
- ./zoneinfo/US/Mountain | ||
- ./zoneinfo/US/Pactific |
@@ -87,1 +87,42 @@ var test = require('tape'); | ||
}); | ||
var locale = require('../locales/sv'), | ||
tzStockholm = require('../').factory(require('../zoneinfo/Europe/Stockholm')); | ||
function twoDigits(val) { | ||
return val >= 10 ? val : '0' + val; | ||
} | ||
function printLong(date) { | ||
return [ | ||
locale.days[date.getDay()].slice(0,3), | ||
date.getDate(), | ||
locale.months[date.getMonth()], | ||
date.getFullYear(), | ||
[ date.getHours(), date.getMinutes() ].map(twoDigits).join(':'), | ||
date.tz && date.tz[1] | ||
].join(' '); | ||
} | ||
function printShort(date) { | ||
var dateStr = [ | ||
date.getFullYear(), | ||
date.getMonth() + 1, | ||
date.getDate() | ||
].map(twoDigits).join('-'); | ||
var timeStr = [ date.getHours(), date.getMinutes() ].map(twoDigits).join(':'); | ||
return dateStr + ' ' + timeStr; | ||
} | ||
//test('tz: Custom Output', function(t) | ||
// | ||
console.log(printLong(tzStockholm.to('2016-01-31T12:00:00.000Z')));// fre 1 januari 2016 13:00 CET | ||
console.log(printShort(tzStockholm.to('2016-01-31T12:00:00.000Z')));// 2016-01-01 13:00 | ||
console.log(tzStockholm.to('2016-01-31T12:00:00.000Z').toLocaleString('sv'));// 2016-01-01 13:00:00 | ||
console.log(tzStockholm.to('2016-01-31T12:00:00.000Z').toLocaleString('en-GB'));// 01/01/2016, 13:00:00 | ||
console.log(tzStockholm.to('2016-01-31T12:00:00.000Z').toLocaleString('en-US'));// 1/1/2016, 1:00:00 PM | ||
29741
134
573
332