Permalink
Browse files

Merge pull request #120 from moment/moment-timezone-0-1-0

Moment Timezone 0.1.0 site updates
  • Loading branch information...
2 parents 917aec9 + 1958df4 commit 53ae623eb0eb7f5b382e5547fac7983d1eb59204 @timrwood timrwood committed Jun 24, 2014
Showing with 901 additions and 112 deletions.
  1. +2 −1 assets/css/_global.scss
  2. +0 −2 assets/js/timezone-data-end.js
  3. +0 −2 assets/js/timezone-data-start.js
  4. +10 −9 assets/js/timezone-home.js
  5. +1 −0 assets/js/timezone-test-end.js
  6. +6 −0 assets/js/timezone-test-start.js
  7. +15 −10 data/size.js
  8. +4 −2 docs/moment-timezone/00-use-it/00-intro.md
  9. +3 −4 docs/moment-timezone/00-use-it/01-node-js.md
  10. +8 −7 docs/moment-timezone/00-use-it/02-browser.md
  11. +9 −14 docs/moment-timezone/00-use-it/03-require-js.md
  12. +0 −5 docs/moment-timezone/01-how-to/00-intro.md
  13. +0 −14 docs/moment-timezone/01-how-to/01-constructor.md
  14. +0 −24 docs/moment-timezone/01-how-to/02-mutator.md
  15. +9 −0 docs/moment-timezone/01-using-timezones/00-intro.md
  16. +67 −0 docs/moment-timezone/01-using-timezones/01-parsing-in-zone.md
  17. +67 −0 docs/moment-timezone/01-using-timezones/02-parsing-ambiguous-inputs.md
  18. +24 −0 docs/moment-timezone/01-using-timezones/03-converting-to-zone.md
  19. +102 −0 docs/moment-timezone/01-using-timezones/04-formatting.md
  20. +19 −0 docs/moment-timezone/02-zone-object/00-intro.md
  21. +7 −0 docs/moment-timezone/02-zone-object/01-name.md
  22. +12 −0 docs/moment-timezone/02-zone-object/02-abbr.md
  23. +12 −0 docs/moment-timezone/02-zone-object/03-offset.md
  24. +31 −0 docs/moment-timezone/02-zone-object/04-parse.md
  25. +6 −0 docs/moment-timezone/03-data-formats/00-intro.md
  26. +24 −0 docs/moment-timezone/03-data-formats/01-unpacked-format.md
  27. +57 −0 docs/moment-timezone/03-data-formats/02-packed-format.md
  28. +15 −0 docs/moment-timezone/03-data-formats/03-link-format.md
  29. +6 −0 docs/moment-timezone/04-data-loading/00-intro.md
  30. +21 −0 docs/moment-timezone/04-data-loading/01-adding-a-zone.md
  31. +24 −0 docs/moment-timezone/04-data-loading/02-adding-a-link.md
  32. +40 −0 docs/moment-timezone/04-data-loading/03-loading-a-data-bundle.md
  33. +14 −0 docs/moment-timezone/04-data-loading/04-checking-if-a-zone-exists.md
  34. +11 −0 docs/moment-timezone/04-data-loading/05-getting-zone-names.md
  35. +25 −0 docs/moment-timezone/05-data-utilities/00-intro.md
  36. +18 −0 docs/moment-timezone/05-data-utilities/01-pack.md
  37. +20 −0 docs/moment-timezone/05-data-utilities/02-unpack.md
  38. +38 −0 docs/moment-timezone/05-data-utilities/03-pack-base-60.md
  39. +16 −0 docs/moment-timezone/05-data-utilities/04-unpack-base-60.md
  40. +32 −0 docs/moment-timezone/05-data-utilities/05-create-links.md
  41. +27 −0 docs/moment-timezone/05-data-utilities/06-filter-years.md
  42. +14 −0 docs/moment-timezone/05-data-utilities/07-filter-link-pack.md
  43. +1 −1 libs/moment-timezone
  44. +17 −0 pages/moment-timezone/data.hbs
  45. +31 −2 pages/moment-timezone/index.hbs
  46. +1 −1 pages/moment-timezone/tests.hbs
  47. +35 −14 tasks/js.js
View
@@ -104,7 +104,8 @@ code {
padding: 1px 4px;
background: rgba($black, 0.03);
border-radius: 3px;
- border: 1px solid rgba($black, 0.15);
+ border: 1px solid rgba($black, 0.1);
+ font-size: 14px;
}
pre code {
@@ -1,2 +0,0 @@
- moment.tz.add(window.momentTZData);
-}());
@@ -1,2 +0,0 @@
-(function(){
- window.momentTZData =
View
@@ -1,5 +1,5 @@
(function(){
- moment.lang("en");
+ moment.lang("en");
var $map = $('.map-inset'),
$labelName = $('.map-label-name'),
@@ -8,7 +8,6 @@
$axisY = $('.map-axis-y'),
width = $map.outerWidth(),
height = $map.outerHeight(),
- i,
lastCenter,
centers = [];
@@ -28,15 +27,15 @@
lastCenter = center;
}
- function Center (data, name) {
- this.x = (180 + data.lon) / 360;
+ function Center (data) {
+ this.name = data.name;
+ this.x = (180 + data.long) / 360;
this.y = (90 - data.lat) / 180;
this.dom = $('<span>').appendTo($map).css({
left: this.x * 100 + '%',
top: this.y * 100 + '%'
});
- this.name = name;
- if (name === 'America/Los_Angeles') {
+ if (this.name === 'America/Los_Angeles') {
changeCenter(this);
}
}
@@ -59,9 +58,11 @@
}
};
- for (i in window.momentTZData.meta) {
- centers.push(new Center(window.momentTZData.meta[i], i));
- }
+ $.getJSON('/data/moment-timezone-meta.json').then(function (data) {
+ for (var i = 0; i < data.length; i++) {
+ centers.push(new Center(data[i]));
+ }
+ });
$('.map-inset').mousemove(function (e) {
var offset = $(this).offset(),
@@ -0,0 +1 @@
+}());
@@ -0,0 +1,6 @@
+(function(){
+ var module = {};
+ var require = function(str){
+ return str.indexOf('helper') > -1 ? module.exports : window.moment;
+ }
+ var exports = {};
View
@@ -1,7 +1,7 @@
var fs = require('fs'),
gzipSize = require('gzip-size'),
- moment = require('../libs/moment/moment.js'),
- timezone = require('../libs/moment-timezone/moment-timezone.js').tz;
+ moment = require('../libs/moment'),
+ timezone = require('../libs/moment-timezone').tz;
function size (file) {
var src = fs.readFileSync('./libs/' + file + '.js', 'utf8');
@@ -13,12 +13,17 @@ function size (file) {
}
module.exports = {
- moment : size('moment/moment'),
- moment_min : size('moment/min/moment.min'),
- moment_with_langs : size('moment/min/moment-with-langs'),
- moment_with_langs_min : size('moment/min/moment-with-langs.min'),
- moment_timezone : size('moment-timezone/moment-timezone'),
- moment_timezone_min : size('moment-timezone/moment-timezone'),
- moment_version : moment.version,
- moment_timezone_version : timezone.version
+ moment : size('moment/moment'),
+ moment_min : size('moment/min/moment.min'),
+ moment_with_langs : size('moment/min/moment-with-langs'),
+ moment_with_langs_min : size('moment/min/moment-with-langs.min'),
+ moment_timezone : size('moment-timezone/moment-timezone'),
+ moment_timezone_min : size('moment-timezone/builds/moment-timezone.min'),
+ moment_timezone_with_data : size('moment-timezone/builds/moment-timezone-with-data'),
+ moment_timezone_with_data_min : size('moment-timezone/builds/moment-timezone-with-data.min'),
+ moment_timezone_with_data_2010_2020 : size('moment-timezone/builds/moment-timezone-with-data-2010-2020'),
+ moment_timezone_with_data_2010_2020_min : size('moment-timezone/builds/moment-timezone-with-data-2010-2020.min'),
+ moment_version : moment.version,
+ moment_timezone_version : timezone.version,
+ moment_timezone_data_version : timezone.dataVersion
};
@@ -3,6 +3,8 @@ title: Where to use it
---
-In order to use moment-timezone, you will need `moment@2.6.0` or greater, the core `moment-timezone` library, and the `moment-timezone` data.
+To use moment-timezone, you will need `moment@2.6.0+`, `moment-timezone.js`, and the `moment-timezone` data.
-You can use the data builder at [momentjs.com/timezone/data/](/timezone/data/) to construct a data set with only the zones needed.
+For convenience, there are builds available on [momentjs.com/timezone/](/timezone/) with all the zone data or a subset of the data with support for only 2010-2020.
+
+You can also use the data builder at [momentjs.com/timezone/data/](/timezone/data/) to construct a data set with only the zones and years needed.
@@ -1,11 +1,10 @@
---
title: Node.js
+signature: |
+ npm install moment-timezone
---
-
-```
-npm install moment-timezone
-```
+In Node.js, all the data is preloaded. No additional code is needed for loading data.
```javascript
var moment = require('moment-timezone');
@@ -1,13 +1,14 @@
---
title: Browser
+signature: |
+ <script src="moment.js"></script>
+ <script src="moment-timezone-with-data.js"></script>
---
+When using Moment Timezone in the browser, you will need to load the data as well as the library.
-```html
-<script src="moment.js"></script>
-<script src="moment-timezone.js"></script>
-<script src="moment-timezone-data.js"></script>
-<script>
- moment().tz("America/Los_Angeles").format();
-</script>
+You can either use the prebuilt library and data files linked on [the homepage](/timezone/) or build a subset of the data yourself using the [data builder](/timezone/data/).
+
+```js
+moment().tz("America/Los_Angeles").format();
```
@@ -1,17 +1,12 @@
---
title: Require.js
+signature: |
+ require.config({
+ paths: {
+ "moment": "path/to/moment"
+ }
+ });
+ define(["path/to/moment-timezone-with-data"], function (moment) {
+ moment().tz("America/Los_Angeles").format();
+ });
---
-
-
-```javascript
-require.config({
- paths: {
- "moment": "path/to/moment",
- "moment-timezone": "path/to/moment-timezone",
- "moment-timezone-data": "path/to/moment-timezone-data"
- }
-});
-define(["moment-timezone", "moment-timezone-data"], function (moment) {
- moment().tz("America/Los_Angeles").format();
-});
-```
@@ -1,5 +0,0 @@
----
-title: How to use it
----
-
-
@@ -1,14 +0,0 @@
----
-title: Constructor
-signature: |
- moment.tz(..., String);
----
-
-
-The `moment.tz` constructor takes all the same arguments as the `moment`
-constructor, but will interpret the last argument as a time zone identifier.
-
-```javascript
-moment.tz("2013-11-18 11:55", "America/Toronto").format(); // "2013-11-18T11:55:00-05:00"
-moment.tz(new Date(2013, 11, 18), "America/Toronto").format(); // "2013-12-18T00:00:00-05:00"
-```
@@ -1,24 +0,0 @@
----
-title: Mutator
-signature: |
- moment(...).tz(String);
----
-
-
-The `.tz` mutator will set the timezone to the provided time zone identifier and
-update the offset.
-
-```javascript
-moment("2013-11-18").tz("America/Toronto").zone(); // 300
-moment("2013-11-18").tz("Europe/Berlin").zone(); // -60
-```
-
-This information is used consistently in other operations, like calculating the
-start of the day.
-
-```javascript
-var m = moment("2013-11-18 11:55");
-m.tz("America/Toronto").format(); // "2013-11-18T11:55:00-05:00"
-m.startOf("day").format(); // "2013-11-18T00:00:00-05:00"
-m.tz("Europe/Berlin").format(); // "2013-11-18T06:00:00+01:00"
-```
@@ -0,0 +1,9 @@
+---
+title: Using Timezones
+---
+
+There are two interfaces for using timezones with Moment.js.
+
+`moment.tz(..., String)` is used to create a moment with a timezone, and `moment().tz(String)` is used to change the timezone on an existing moment.
+
+
@@ -0,0 +1,67 @@
+---
+title: Parsing in Zone
+signature: |
+ moment.tz(..., String);
+---
+
+
+The `moment.tz` constructor takes all the same arguments as the `moment`
+constructor, but uses the last argument as a time zone identifier.
+
+```js
+var a = moment.tz("2013-11-18 11:55", "America/Toronto");
+var b = moment.tz("May 12th 2014 8PM", "MMM Do YYYY hA", "America/Toronto");
+var c = moment.tz(1403454068850, "America/Toronto");
+a.format(); // 2013-11-18T11:55:00-05:00
+b.format(); // 2014-05-12T20:00:00-04:00
+c.format(); // 2014-06-22T12:21:08-04:00
+```
+
+This constructor is DST aware, and will use the correct offset when parsing.
+
+```js
+moment.tz("2013-12-01", "America/Los_Angeles").format(); // 2013-12-01T00:00:00-08:00
+moment.tz("2013-06-01", "America/Los_Angeles").format(); // 2013-06-01T00:00:00-07:00
+```
+
+The offset is only taken into consideration when constructing with an array,
+string without offset, or object.
+
+```js
+var arr = [2013, 5, 1],
+ str = "2013-12-01"
+ obj = { year : 2013, month : 5, day : 1 };
+
+moment.tz(arr, "America/Los_Angeles").format(); // 2013-06-01T00:00:00-07:00
+moment.tz(str, "America/Los_Angeles").format(); // 2013-06-01T00:00:00-07:00
+moment.tz(obj, "America/Los_Angeles").format(); // 2013-06-01T00:00:00-07:00
+
+moment.tz(arr, "America/New_York").format(); // 2013-06-01T00:00:00-04:00
+moment.tz(str, "America/New_York").format(); // 2013-06-01T00:00:00-04:00
+moment.tz(obj, "America/New_York").format(); // 2013-06-01T00:00:00-04:00
+```
+
+If the input string contains an offset, it is used instead for parsing. The parsed moment
+is then converted to the target zone.
+
+```js
+var zone = "America/Los_Angeles";
+moment.tz('2013-06-01T00:00:00', zone).format(); // 2013-06-01T00:00:00-07:00
+moment.tz('2013-06-01T00:00:00-04:00', zone).format(); // 2013-05-31T21:00:00-07:00
+moment.tz('2013-06-01T00:00:00+00:00', zone).format(); // 2013-05-31T17:00:00-07:00
+```
+
+Unix timestamps and `Date` objects refer to specific points in time, thus it doesn't
+make sense to use the timezone offset when constructing. Using `moment.tz(Number|Date, zone)`
+is functionally equivalent to `moment(Number|Date).tz(zone)`.
+
+```js
+var timestamp = 1403454068850,
+ date = new Date(timestamp);
+
+moment.tz(timestamp, "America/Los_Angeles").format(); // 2014-06-22T09:21:08-07:00
+moment(timestamp).tz("America/Los_Angeles").format(); // 2014-06-22T09:21:08-07:00
+
+moment.tz(date, "America/Los_Angeles").format(); // 2014-06-22T09:21:08-07:00
+moment(date).tz("America/Los_Angeles").format(); // 2014-06-22T09:21:08-07:00
+```
@@ -0,0 +1,67 @@
+---
+title: Parsing Ambiguities
+---
+
+
+
+Due to Daylight Saving Time, there is a possibility that a time either does
+not exist, or has existed twice.
+
+In the spring, at the start of DST, clocks move forward an hour. In reality though, it
+is not time that is moving, it is the offset moving.
+
+Moving the offset forward gives the illusion that an hour has disappeared. As the
+clock ticks, you can see it move from `1:58` to `1:59` to `3:00`. It is easier to
+see what is actually happening when you include the offset.
+
+```
+1:58 -8
+1:59 -8
+3:00 -7
+3:01 -7
+```
+
+The result is that any time between `1:59:59` and `3:00:00` never actually happened.
+Moment Timezone accounts for this. If you try to parse a time that never existed,
+it will round down an hour.
+
+```js
+moment.tz("2012-03-11 01:59:59", "America/New_York"); // 2012-03-11T01:59:59-05:00
+moment.tz("2012-03-11 02:00:00", "America/New_York"); // 2012-03-11T01:00:00-05:00
+moment.tz("2012-03-11 02:59:59", "America/New_York"); // 2012-03-11T01:59:59-05:00
+moment.tz("2012-03-11 03:00:00", "America/New_York"); // 2012-03-11T03:00:00-04:00
+```
+
+In the fall, at the end of DST, clocks move backward an hour. Again, time is not
+moving backwards, only the offset is. In this case, the illusion is that an hour repeats itself.
+
+Again, it is easier to see what is actually happening when you include the offset.
+
+```
+1:58 -7
+1:59 -7
+1:00 -8
+1:01 -8
+```
+
+Moment Timezone handles this by always using the earlier instance of a duplicated hour.
+
+```js
+moment.tz("2012-11-04 00:59:59", "America/New_York"); // 2012-11-04T00:59:59-04:00
+moment.tz("2012-11-04 01:00:00", "America/New_York"); // 2012-11-04T01:00:00-04:00
+moment.tz("2012-11-04 01:59:59", "America/New_York"); // 2012-11-04T01:59:59-04:00
+moment.tz("2012-11-04 02:00:00", "America/New_York"); // 2012-11-04T02:00:00-05:00
+```
+
+You won't be able to create a moment with the later instance of the duplicated hour unless you
+include the offset when parsing.
+
+```js
+moment.tz("2012-11-04 01:00:00-04:00", "America/New_York"); // 2012-11-04T01:00:00-04:00
+moment.tz("2012-11-04 01:00:00-05:00", "America/New_York"); // 2012-11-04T01:00:00-05:00
+```
+
+
+
+
+
Oops, something went wrong.

0 comments on commit 53ae623

Please sign in to comment.