mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-11 17:02:28 +00:00
Handle timestamps in daylight saving time
Add the Moment Timezone library. Add a script for managing libraries, like in MediaWiki core. Depends-On: I9a59a6ad01850b30327e4215f2be61b8d1c41277 Change-Id: I64bc79e7d0ccdf42b006e5a225c8aa70ea5f4e15
This commit is contained in:
parent
3dc5d79b20
commit
db80e48933
|
@ -15,7 +15,8 @@ module.exports = function ( grunt ) {
|
|||
},
|
||||
all: [
|
||||
'*.{js,json}',
|
||||
'modules/**/*.{js,json}'
|
||||
'modules/**/*.{js,json}',
|
||||
'!modules/lib/**'
|
||||
]
|
||||
},
|
||||
stylelint: {
|
||||
|
|
|
@ -23,12 +23,14 @@
|
|||
"packageFiles": [
|
||||
"dt.init.js",
|
||||
"parser.js",
|
||||
"lib/moment-timezone/moment-timezone-with-data-1970-2030.js",
|
||||
{
|
||||
"name": "data.json",
|
||||
"callback": "DiscussionToolsHooks::getLocalData"
|
||||
}
|
||||
],
|
||||
"dependencies": [
|
||||
"moment",
|
||||
"mediawiki.util",
|
||||
"mediawiki.Uri",
|
||||
"mediawiki.Title",
|
||||
|
|
|
@ -55,29 +55,40 @@ class DiscussionToolsHooks {
|
|||
|
||||
// ApiQuerySiteinfo
|
||||
$data['localTimezone'] = $config->get( 'Localtimezone' );
|
||||
// This changes magically with DST
|
||||
$data['localTimezoneOffset'] = (int)$config->get( 'LocalTZoffset' );
|
||||
|
||||
$data['specialContributionsName'] = SpecialPageFactory::getLocalNameFor( 'Contributions' );
|
||||
|
||||
// TODO: This should only include abbreviations for $wgLocaltimezone, but timezones can have
|
||||
// multiple abbreviations (non-DST and DST) and we can't get them easily? For example CET and
|
||||
// CEST for 'Europe/Warsaw'.
|
||||
$data['timezones'] = array_map( function ( $tzMsg ) {
|
||||
// MWTimestamp::getTimezoneMessage()
|
||||
// Parser::pstPass2()
|
||||
// Messages used here: 'timezone-utc' and so on
|
||||
$key = 'timezone-' . strtolower( trim( $tzMsg ) );
|
||||
$msg = wfMessage( $key )->inContentLanguage();
|
||||
// TODO: This probably causes a similar issue to https://phabricator.wikimedia.org/T221294,
|
||||
// but we *must* check the message existence in the database, because the messages are not
|
||||
// actually defined by MediaWiki core for any timezone other than UTC...
|
||||
if ( $msg->exists() ) {
|
||||
return $msg->text();
|
||||
$localTimezone = $config->get( 'Localtimezone' );
|
||||
// Return only timezone abbreviations for the local timezone (there will often be two, for
|
||||
// non-DST and DST timestamps, and sometimes more due to historical data, but that's okay).
|
||||
$timezoneAbbrs = array_keys( array_filter(
|
||||
timezone_abbreviations_list(),
|
||||
function ( $timezones ) use ( $localTimezone ) {
|
||||
foreach ( $timezones as $tz ) {
|
||||
if ( $tz['timezone_id'] === $localTimezone ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return strtoupper( $tzMsg );
|
||||
}, array_keys( timezone_abbreviations_list() ) );
|
||||
) );
|
||||
$data['timezones'] = array_combine(
|
||||
array_map( function ( $tzMsg ) {
|
||||
// MWTimestamp::getTimezoneMessage()
|
||||
// Parser::pstPass2()
|
||||
// Messages used here: 'timezone-utc' and so on
|
||||
$key = 'timezone-' . strtolower( trim( $tzMsg ) );
|
||||
$msg = wfMessage( $key )->inContentLanguage();
|
||||
// TODO: This probably causes a similar issue to https://phabricator.wikimedia.org/T221294,
|
||||
// but we *must* check the message existence in the database, because the messages are not
|
||||
// actually defined by MediaWiki core for any timezone other than UTC...
|
||||
if ( $msg->exists() ) {
|
||||
return $msg->text();
|
||||
}
|
||||
return strtoupper( $tzMsg );
|
||||
}, $timezoneAbbrs ),
|
||||
array_map( 'strtoupper', $timezoneAbbrs )
|
||||
);
|
||||
|
||||
// Messages in content language
|
||||
$messagesKeys = array_merge(
|
||||
|
|
20
maintenance/manageForeignResources.php
Normal file
20
maintenance/manageForeignResources.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
$IP = getenv( 'MW_INSTALL_PATH' );
|
||||
if ( $IP === false ) {
|
||||
$IP = __DIR__ . '/../../..';
|
||||
}
|
||||
require_once "$IP/maintenance/Maintenance.php";
|
||||
|
||||
class DiscussionToolsManageForeignResources extends Maintenance {
|
||||
public function execute() {
|
||||
$frm = new ForeignResourceManager(
|
||||
__DIR__ . '/../modules/lib/foreign-resources.yaml',
|
||||
__DIR__ . '/../modules/lib'
|
||||
);
|
||||
return $frm->run( 'update', 'all' );
|
||||
}
|
||||
}
|
||||
|
||||
$maintClass = DiscussionToolsManageForeignResources::class;
|
||||
require_once RUN_MAINTENANCE_IF_MAIN;
|
10
modules/lib/foreign-resources.yaml
Normal file
10
modules/lib/foreign-resources.yaml
Normal file
|
@ -0,0 +1,10 @@
|
|||
moment-timezone:
|
||||
type: tar
|
||||
src: https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.27.tgz
|
||||
integrity: sha512-EIKQs7h5sAsjhPCqN6ggx6cEbs94GK050254TIJySD1bzoM5JTYDwAU1IoVOeTOL6Gm27kYJ51/uuvq1kIlrbw==
|
||||
|
||||
dest:
|
||||
package/builds/moment-timezone-with-data-1970-2030.js:
|
||||
package/changelog.md:
|
||||
package/LICENSE:
|
||||
package/README.md:
|
20
modules/lib/moment-timezone/LICENSE
Normal file
20
modules/lib/moment-timezone/LICENSE
Normal file
|
@ -0,0 +1,20 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) JS Foundation and other contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
36
modules/lib/moment-timezone/README.md
Normal file
36
modules/lib/moment-timezone/README.md
Normal file
|
@ -0,0 +1,36 @@
|
|||
# [Moment Timezone](http://momentjs.com/timezone)
|
||||
|
||||
[![Join the chat at https://gitter.im/moment/moment-timezone](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/moment/moment-timezone?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
|
||||
[![NPM version][npm-version-image]][npm-url] [![NPM downloads][npm-downloads-image]][npm-url] [![MIT License][license-image]][license-url] [![Build Status][travis-image]][travis-url]
|
||||
|
||||
IANA Time Zone Database + [Moment.js](http://momentjs.com).
|
||||
|
||||
```js
|
||||
var june = moment("2014-06-01T12:00:00Z");
|
||||
june.tz('America/Los_Angeles').format('ha z'); // 5am PDT
|
||||
june.tz('America/New_York').format('ha z'); // 8am EDT
|
||||
june.tz('Asia/Tokyo').format('ha z'); // 9pm JST
|
||||
june.tz('Australia/Sydney').format('ha z'); // 10pm EST
|
||||
|
||||
var dec = moment("2014-12-01T12:00:00Z");
|
||||
dec.tz('America/Los_Angeles').format('ha z'); // 4am PST
|
||||
dec.tz('America/New_York').format('ha z'); // 7am EST
|
||||
dec.tz('Asia/Tokyo').format('ha z'); // 9pm JST
|
||||
dec.tz('Australia/Sydney').format('ha z'); // 11pm EST
|
||||
```
|
||||
|
||||
#### [Contribute code or compile time zone data](contributing.md)
|
||||
|
||||
#### [Read the changelog](changelog.md)
|
||||
|
||||
|
||||
[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat
|
||||
[license-url]: LICENSE
|
||||
|
||||
[npm-url]: https://npmjs.org/package/moment-timezone
|
||||
[npm-version-image]: http://img.shields.io/npm/v/moment-timezone.svg?style=flat
|
||||
[npm-downloads-image]: http://img.shields.io/npm/dm/moment-timezone.svg?style=flat
|
||||
|
||||
[travis-url]: http://travis-ci.org/moment/moment-timezone
|
||||
[travis-image]: http://img.shields.io/travis/moment/moment-timezone/develop.svg?style=flat
|
194
modules/lib/moment-timezone/changelog.md
Normal file
194
modules/lib/moment-timezone/changelog.md
Normal file
|
@ -0,0 +1,194 @@
|
|||
### `0.5.27` _2019-10-14_
|
||||
* Updated data to IANA TZDB `2019c`
|
||||
|
||||
### `0.5.26` _2019-06-06_
|
||||
* Updated data to IANA TZDB `2019b`
|
||||
* Fix: stabilize Array.sort [#762](https://github.com/moment/moment-timezone/pull/762)
|
||||
|
||||
### `0.5.25` _2019-04-17_
|
||||
* Fix `moment.tz.dataVersion` to return `2019a` [#742](https://github.com/moment/moment-timezone/issues/742)
|
||||
* Update path in bower.json
|
||||
|
||||
### `0.5.24` _2019-04-17_
|
||||
* Updated data to IANA TZDB `2019a` [#737](https://github.com/moment/moment-timezone/issues/737)
|
||||
* Start shipping both a 1970-1930 file and a rolling 10-year file [#614](https://github.com/moment/moment-timezone/issues/614) [#697](https://github.com/moment/moment-timezone/issues/697)
|
||||
* Fixed bug where `_z` time zone name was not cleared with `.local()` or `.utcOffset(offset)` [#738](https://github.com/moment/moment-timezone/issues/738)
|
||||
|
||||
### `0.5.23` _2018-10-28_
|
||||
* Fix minor issue with tz guessing in Russia [#691](https://github.com/moment/moment-timezone/pull/691)
|
||||
|
||||
### `0.5.22` _2018-10-28_
|
||||
* Updated data to IANA TZDB `2018g` [#689](https://github.com/moment/moment-timezone/pull/689)
|
||||
* Fix issue with missing LMT entries for some zones, and fix data builds on Linux and Windows [#308](https://github.com/moment/moment-timezone/issues/308)
|
||||
|
||||
### `0.5.21` _2018-06-23_
|
||||
* Bugfix: revert breaking change introduced in 0.5.18
|
||||
|
||||
### `0.5.20` _2018-06-18_
|
||||
* Bugfix: accidentally commented code
|
||||
|
||||
### `0.5.19` _2018-06-18_
|
||||
* Revert: moved moment to peerDependencies
|
||||
|
||||
### `0.5.18` _2018-06-18_
|
||||
* Return error when timezone name is not a string.
|
||||
* Moved moment to peerDependencies [#628](https://github.com/moment/moment-timezone/pull/628)
|
||||
* Prefer nodejs to amd declaration [#573](https://github.com/moment/moment-timezone/pull/573)
|
||||
|
||||
### `0.5.17` _2018-05-12_
|
||||
* Updated data to IANA TZDB `2018d`. [#616](https://github.com/moment/moment-timezone/pull/616)
|
||||
|
||||
### `0.5.16` _2018-04-18_
|
||||
* Fixed Etc/UTC timezone recognition, updated tests. [#599](https://github.com/moment/moment-timezone/pull/599)
|
||||
* Updated minified files to contain IANA TZDB `2018d` data
|
||||
|
||||
### `0.5.15` _2018-04-17_
|
||||
* Updated data to IANA TZDB `2018d`. [#596](https://github.com/moment/moment-timezone/pull/596)
|
||||
|
||||
### `0.5.14` _2017-10-30_
|
||||
* Ensure Intl response is valid when guessing time zone. [#553](https://github.com/moment/moment-timezone/pull/553)
|
||||
* Updated data to IANA TZDB `2017c`. [#552](https://github.com/moment/moment-timezone/pull/552)
|
||||
* Convert to tz keeping wall time [#505](https://github.com/moment/moment-timezone/pull/505)
|
||||
* Make all time zones available for guessing. [#483](https://github.com/moment/moment-timezone/pull/483)
|
||||
* zone.offset has been deprecated in favor of zone.utcOffset [#398](https://github.com/moment/moment-timezone/pull/398)
|
||||
* Check for timestamp formats when parsing [#348](https://github.com/moment/moment-timezone/pull/348)
|
||||
|
||||
### `0.5.13` _2017-04-04_
|
||||
* Bumped version to address Bower cache issues with last release. [#474](https://github.com/moment/moment-timezone/issues/474)
|
||||
* (No actual changes otherwise)
|
||||
|
||||
### `0.5.12` _2017-04-02_
|
||||
* Updated data to IANA TZDB `2017b`. [#422](https://github.com/moment/moment-timezone/pull/460)
|
||||
* Build the truncated data file as 2012-2022 (+/- 5 years).
|
||||
|
||||
### `0.5.11` _2016-12-23_
|
||||
* Remove log statement when data is loaded twice. [#352](https://github.com/moment/moment-timezone/pull/352)
|
||||
|
||||
### `0.5.10` _2016-11-27_
|
||||
* Updated data to IANA TZDB `2016j`. [#422](https://github.com/moment/moment-timezone/pull/422)
|
||||
|
||||
### `0.5.9` _2016-11-03_
|
||||
* Fixed the output of `moment.tz.version`. [#413](https://github.com/moment/moment-timezone/issues/413)
|
||||
|
||||
### `0.5.8` _2016-11-03_
|
||||
* Updated data to IANA TZDB `2016i`. [#411](https://github.com/moment/moment-timezone/pull/411)
|
||||
|
||||
### `0.5.7` _2016-10-21_
|
||||
* Updated data to IANA TZDB `2016h`. [#403](https://github.com/moment/moment-timezone/pull/403)
|
||||
|
||||
### `0.5.6` _2016-10-08_
|
||||
* Updated data to IANA TZDB `2016g`. [#394](https://github.com/moment/moment-timezone/pull/394)
|
||||
|
||||
### `0.5.5` _2016-07-24_
|
||||
* Updated data to IANA TZDB `2016f`. [#360](https://github.com/moment/moment-timezone/pull/360)
|
||||
|
||||
### `0.5.4` _2016-05-03_
|
||||
* Updated data to IANA TZDB `2016d`. [#336](https://github.com/moment/moment-timezone/pull/336)
|
||||
* Ignore the results from `Intl.DateTimeFormat().resolvedOptions().timeZone` if it is undefined. [#322](https://github.com/moment/moment-timezone/pull/322)
|
||||
|
||||
### `0.5.3` _2016-03-24_
|
||||
* Updated data to IANA TZDB `2016c`. [#321](https://github.com/moment/moment-timezone/pull/321)
|
||||
|
||||
### `0.5.2` _2016-03-15_
|
||||
* Updated data to IANA TZDB `2016b`. [#315](https://github.com/moment/moment-timezone/pull/315)
|
||||
|
||||
### `0.5.1` _2016-03-01_
|
||||
* Updated data to IANA TZDB `2016a`. [#299](https://github.com/moment/moment-timezone/pull/299)
|
||||
* Fixed bug when `Date#toTimeString` did not return a known format. [#302](https://github.com/moment/moment-timezone/pull/302) [#303](https://github.com/moment/moment-timezone/pull/303)
|
||||
* Added lookup on `Intl.DateTimeFormat().resolvedOptions().timeZone` to `moment.tz.guess()`. [#304](https://github.com/moment/moment-timezone/pull/304) [#291](https://github.com/moment/moment-timezone/pull/291)
|
||||
|
||||
### `0.5.0` _2015-12-28_
|
||||
* Added support for guessing the user's timezone via `moment.tz.guess()`. [#285](https://github.com/moment/moment-timezone/pull/285)
|
||||
* Fixed UMD export issue when there was an html element with `id=exports`. [#275](https://github.com/moment/moment-timezone/pull/275)
|
||||
* Removed jspm specific dependencies from `package.json`. [#284](https://github.com/moment/moment-timezone/pull/284)
|
||||
|
||||
### `0.4.1` _2015-10-07_
|
||||
* Updated data to IANA TZDB `2015e`. [#253](https://github.com/moment/moment-timezone/pull/253)
|
||||
* Updated data to IANA TZDB `2015f`. [#253](https://github.com/moment/moment-timezone/pull/253)
|
||||
* Updated data to IANA TZDB `2015g`. [#255](https://github.com/moment/moment-timezone/pull/255)
|
||||
* Added jspm dependencies for moment. [#234](https://github.com/moment/moment-timezone/pull/234)
|
||||
* Included builds directory in npm. [#237](https://github.com/moment/moment-timezone/pull/237)
|
||||
* Removed version field from bower.json. [#230](https://github.com/moment/moment-timezone/pull/230)
|
||||
|
||||
### `0.4.0` _2015-05-30_
|
||||
* Updated data to IANA TZDB `2015b`. [#201](https://github.com/moment/moment-timezone/pull/201)
|
||||
* Updated data to IANA TZDB `2015c`. [#214](https://github.com/moment/moment-timezone/pull/214)
|
||||
* Updated data to IANA TZDB `2015d`. [#214](https://github.com/moment/moment-timezone/pull/214)
|
||||
* Updated zone getter to allow lazy unpacking to improve initial page load times. [#216](https://github.com/moment/moment-timezone/pull/216)
|
||||
* Added a `package.json` `jspm:main` entry point. [#194](https://github.com/moment/moment-timezone/pull/194)
|
||||
* Added `composer.json`. [#222](https://github.com/moment/moment-timezone/pull/222)
|
||||
* Added an error message when trying to load moment-timezone twice. [#212](https://github.com/moment/moment-timezone/pull/212)
|
||||
|
||||
### `0.3.1` _2015-03-16_
|
||||
* Updated data to IANA TZDB `2015a`. [#183](https://github.com/moment/moment-timezone/pull/183)
|
||||
|
||||
### `0.3.0` _2015-01-13_
|
||||
|
||||
* *Breaking:* Added country data to the `meta/*.json` files. Restructured the data to support multiple countries per zone. [#162](https://github.com/moment/moment-timezone/pull/162)
|
||||
* Added the ability to set a default timezone for all new moments. [#152](https://github.com/moment/moment-timezone/pull/152)
|
||||
* Fixed a bug when passing a moment with an offset to `moment.tz`. [#169](https://github.com/moment/moment-timezone/pull/169)
|
||||
* Fixed a deprecation in moment core, changing `moment#zone` to `moment#utcOffset`. [#168](https://github.com/moment/moment-timezone/pull/168)
|
||||
|
||||
### `0.2.5` _2014-11-12_
|
||||
* Updated data to IANA TZDB `2014j`. [#151](https://github.com/moment/moment-timezone/pull/151)
|
||||
|
||||
### `0.2.4` _2014-10-20_
|
||||
* Updated data to IANA TZDB `2014i`. [#142](https://github.com/moment/moment-timezone/pull/142)
|
||||
|
||||
### `0.2.3` _2014-10-20_
|
||||
* Updated data to IANA TZDB `2014h`. [#141](https://github.com/moment/moment-timezone/pull/141)
|
||||
|
||||
### `0.2.2` _2014-09-04_
|
||||
* Updated data to IANA TZDB `2014g`. [#126](https://github.com/moment/moment-timezone/pull/126)
|
||||
* Added a warning when using `moment-timezone` with `moment<2.6.0`.
|
||||
|
||||
### `0.2.1` _2014-08-02_
|
||||
* Fixed support for `moment@2.8.1+`.
|
||||
|
||||
### `0.2.0` _2014-07-21_
|
||||
* Added the ability to configure whether ambiguous or invalid input is rolled forward or backward. [#101](https://github.com/moment/moment-timezone/pull/101)
|
||||
* Added `moment>=2.6.0` as a dependency in `bower.json`. [#107](https://github.com/moment/moment-timezone/issues/107)
|
||||
* Fixed getting the name of a zone that was added as a linked zone. [#104](https://github.com/moment/moment-timezone/pull/104)
|
||||
* Added an error message when a zone was not loaded. [#106](https://github.com/moment/moment-timezone/issues/106)
|
||||
|
||||
### `0.1.0` _2014-06-23_
|
||||
* *Breaking:* Changed data format from Zones+Rules to just Zones. [#82](https://github.com/moment/moment-timezone/pull/82)
|
||||
* *Breaking:* Removed `moment.tz.{addRule,addZone,zoneExists,zones}` as they are no longer relevant with the new data format.
|
||||
* Made library 20x faster. [JSPerf results](http://jsperf.com/moment-timezone-0-1-0/2)
|
||||
* Completely rewrote internals to support new data format.
|
||||
* Updated the data collection process to get data directly from http://www.iana.org/time-zones.
|
||||
* Updated data to IANA TZDB `2014e`.
|
||||
* Updated `bower.json` to use a browser specific `main:` entry point.
|
||||
* Added built files with included data.
|
||||
* Added support for accurately parsing input around DST changes. [#93](https://github.com/moment/moment-timezone/pull/93)
|
||||
* Added comprehensive documentation at [momentjs.com/timezone/docs/](http://momentjs.com/timezone/docs/).
|
||||
* Added `moment.tz.link` for linking two identical zones.
|
||||
* Added `moment.tz.zone` for getting a loaded zone.
|
||||
* Added `moment.tz.load` for loading a bundled version of data from the IANA TZDB.
|
||||
* Added `moment.tz.names` for getting the names of all the loaded timezones.
|
||||
* Added `moment.tz.unpack` and `moment.tz.unpackBase60` for unpacking data.
|
||||
* Added `moment-timezone-utils.js` for working with the packed and unpacked data.
|
||||
* Fixed major memory leak. [#79](https://github.com/moment/moment-timezone/issues/79)
|
||||
* Fixed global export to allow use in web workers. [#78](https://github.com/moment/moment-timezone/pull/78)
|
||||
* Fixed global export in browser environments that define `window.module`. [#76](https://github.com/moment/moment-timezone/pull/76)
|
||||
|
||||
### `0.0.6` _2014-04-20_
|
||||
* Fixed issue with preventing loading moment-timezone more than once. [#75](https://github.com/moment/moment-timezone/pull/75)
|
||||
|
||||
### `0.0.5` _2014-04-17_
|
||||
* Improved performance with memoization. [#39](https://github.com/moment/moment-timezone/issues/39)
|
||||
* Published only necessary files to npm. [#46](https://github.com/moment/moment-timezone/issues/46)
|
||||
* Added better handling of timezones around DST. [#53](https://github.com/moment/moment-timezone/issues/53) [#61](https://github.com/moment/moment-timezone/issues/61) [#70](https://github.com/moment/moment-timezone/issues/70)
|
||||
* Added Browserify support. [#41](https://github.com/moment/moment-timezone/issues/41)
|
||||
* Added `moment.tz.zoneExists` [#73](https://github.com/moment/moment-timezone/issues/73)
|
||||
* Fixed cloning moments with a timezone. [#71](https://github.com/moment/moment-timezone/issues/71)
|
||||
* Prevent loading moment-timezone more than once. [#74](https://github.com/moment/moment-timezone/issues/74)
|
||||
|
||||
### `0.0.3` _2013-10-10_
|
||||
* Added Bower support.
|
||||
* Added support for newer versions of moment.
|
||||
* Added support for constructing a moment with a string and zone.
|
||||
* Added more links and timezone names in moment-timezone.json
|
||||
|
||||
### `0.0.1` _2013-07-17_
|
||||
* Initial version.
|
1227
modules/lib/moment-timezone/moment-timezone-with-data-1970-2030.js
Normal file
1227
modules/lib/moment-timezone/moment-timezone-with-data-1970-2030.js
Normal file
File diff suppressed because it is too large
Load diff
|
@ -2,7 +2,9 @@
|
|||
'use strict';
|
||||
|
||||
// DiscussionToolsHooks::getLocalData()
|
||||
var data = require( './data.json' );
|
||||
var
|
||||
data = require( './data.json' ),
|
||||
moment = require( './lib/moment-timezone/moment-timezone-with-data-1970-2030.js' );
|
||||
|
||||
function getMessages( msg ) {
|
||||
return msg.map( function ( code ) {
|
||||
|
@ -23,8 +25,8 @@ function regexpAlternateGroup( array ) {
|
|||
// MediaWiki's languages, namely: D, d, F, G, H, i, j, l, M, n, Y, xg, xkY (and escape characters),
|
||||
// and only dates when MediaWiki existed, let's say 2000 onwards (Thai dates before 1941 are
|
||||
// complicated).
|
||||
function getTimestampRegexp( format, digits ) {
|
||||
var s, p, num, code, endQuote;
|
||||
function getTimestampRegexp( format, digits, tzAbbrs ) {
|
||||
var s, p, num, code, endQuote, tzRegexp, regexp;
|
||||
|
||||
s = '';
|
||||
|
||||
|
@ -129,10 +131,14 @@ function getTimestampRegexp( format, digits ) {
|
|||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
tzRegexp = regexpAlternateGroup( Object.keys( tzAbbrs ) );
|
||||
// Hardcoded parentheses and space like in Parser::pstPass2
|
||||
regexp = s + ' \\(' + tzRegexp + '\\)';
|
||||
|
||||
return regexp;
|
||||
}
|
||||
|
||||
function getTimestampParser( format, digits, tzOffset ) {
|
||||
function getTimestampParser( format, digits, localTimezone, tzAbbrs ) {
|
||||
var p, code, endQuote, matchingGroups = [];
|
||||
for ( p = 0; p < format.length; p++ ) {
|
||||
code = format[ p ];
|
||||
|
@ -193,14 +199,16 @@ function getTimestampParser( format, digits, tzOffset ) {
|
|||
);
|
||||
}
|
||||
|
||||
return function ( match ) {
|
||||
return function timestampParser( match ) {
|
||||
var
|
||||
year = 0,
|
||||
monthIdx = 0,
|
||||
day = 0,
|
||||
hour = 0,
|
||||
minute = 0,
|
||||
i, code, text;
|
||||
tzAbbr,
|
||||
i, code, text,
|
||||
date;
|
||||
for ( i = 0; i < matchingGroups.length; i++ ) {
|
||||
code = matchingGroups[ i ];
|
||||
text = match[ i + 1 ];
|
||||
|
@ -255,31 +263,52 @@ function getTimestampParser( format, digits, tzOffset ) {
|
|||
throw new Error( 'Not implemented' );
|
||||
}
|
||||
}
|
||||
// The last matching group is the timezone abbreviation
|
||||
tzAbbr = tzAbbrs[ match[ i + 1 ] ];
|
||||
|
||||
return new Date( Date.UTC( year, monthIdx, day, hour, minute ) - tzOffset * 60 * 1000 );
|
||||
// Most of the time, the timezone abbreviation is not necessary to parse the date, since we
|
||||
// can assume all times are in the wiki's local timezone.
|
||||
date = moment.tz( [ year, monthIdx, day, hour, minute ], localTimezone );
|
||||
|
||||
// But during the "fall back" at the end of DST, some times will happen twice. Per the docs,
|
||||
// "Moment Timezone handles this by always using the earlier instance of a duplicated hour."
|
||||
// https://momentjs.com/timezone/docs/#/using-timezones/parsing-ambiguous-inputs/
|
||||
|
||||
// Since the timezone abbreviation disambiguates the DST/non-DST times, we can detect when
|
||||
// that behavior was incorrect...
|
||||
if ( date.zoneAbbr() !== tzAbbr ) {
|
||||
// ...and force the correct parsing. I can't find proper documentation for this feature,
|
||||
// but this pull request explains it: https://github.com/moment/moment-timezone/pull/101
|
||||
moment.tz.moveAmbiguousForward = true;
|
||||
date = moment.tz( [ year, monthIdx, day, hour, minute ], localTimezone );
|
||||
moment.tz.moveAmbiguousForward = false;
|
||||
if ( date.zoneAbbr() !== tzAbbr ) {
|
||||
// This should not be possible for "genuine" timestamps generated by MediaWiki.
|
||||
// But bots and humans get it wrong when marking up unsigned comments…
|
||||
// https://pl.wikipedia.org/w/index.php?title=Wikipedia:Kawiarenka/Artykuły&diff=prev&oldid=54772606
|
||||
console.log( 'Timestamp has timezone abbreviation for the wrong time: ' + match[ 0 ] );
|
||||
} else {
|
||||
console.log( 'Ambiguous time at DST switchover was parsed: ' + match[ 0 ] );
|
||||
}
|
||||
}
|
||||
|
||||
return date;
|
||||
};
|
||||
}
|
||||
|
||||
// Parser::pstPass2
|
||||
function getLocalTimestampRegexp() {
|
||||
var
|
||||
df = data.dateFormat,
|
||||
digits = mw.config.get( 'wgTranslateNumerals' ) ? data.digits : null,
|
||||
dfRegexp = getTimestampRegexp( df, digits ? '[' + digits + ']' : '\\d' ),
|
||||
localizedTimezones = data.timezones,
|
||||
// TODO: Timezone abbreviations are not unique so we can't do anything useful with this.
|
||||
tzRegexp = '(?:' + localizedTimezones.map( mw.util.escapeRegExp ).join( '|' ) + ')',
|
||||
regexp = dfRegexp + ' \\(' + tzRegexp + '\\)';
|
||||
return regexp;
|
||||
digitsRegexp = mw.config.get( 'wgTranslateNumerals' ) ? '[' + data.digits + ']' : '\\d',
|
||||
dfRegexp = getTimestampRegexp( df, digitsRegexp, data.timezones );
|
||||
return dfRegexp;
|
||||
}
|
||||
|
||||
function getLocalTimestampParser() {
|
||||
var
|
||||
df = data.dateFormat,
|
||||
digits = mw.config.get( 'wgTranslateNumerals' ) ? data.digits : null,
|
||||
// TODO: Implement DST offsets
|
||||
// TODO: Implement timezone validation
|
||||
parseFunction = getTimestampParser( df, digits, data.localTimezoneOffset );
|
||||
parseFunction = getTimestampParser( df, digits, data.localTimezone, data.timezones );
|
||||
return parseFunction;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue