Import of the watch repository from Pebble

This commit is contained in:
Matthieu Jeanson 2024-12-12 16:43:03 -08:00 committed by Katharine Berry
commit 3b92768480
10334 changed files with 2564465 additions and 0 deletions

3
third_party/timeshift-js/.npmignore vendored Normal file
View file

@ -0,0 +1,3 @@
node_modules/
npm-debug.log

20
third_party/timeshift-js/LICENSE vendored Normal file
View file

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2013 Mobile Wellness Solutions MWS Ltd, Sampo Niskanen
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.

90
third_party/timeshift-js/README.md vendored Normal file
View file

@ -0,0 +1,90 @@
TimeShift.js
============
TimeShift.js allows mocking / overriding JavaScript's Date object so that you can set the current time and timezone. It is meant for creating repeatable tests that utilize the current time or date.
Usage
-----
```javascript
new Date().toString(); // Original Date object
"Fri Aug 09 2013 23:37:42 GMT+0300 (EEST)"
Date = TimeShift.Date; // Overwrite Date object
new Date().toString();
"Fri Aug 09 2013 23:37:43 GMT+0300"
TimeShift.setTimezoneOffset(-60); // Set timezone to GMT+0100 (note the sign)
new Date().toString();
"Fri Aug 09 2013 21:37:44 GMT+0100"
TimeShift.setTime(1328230923000); // Set the time to 2012-02-03 01:02:03 GMT
new Date().toString();
"Fri Feb 03 2012 02:02:03 GMT+0100"
TimeShift.setTimezoneOffset(0); // Set timezone to GMT
new Date().toString();
"Fri Feb 03 2012 01:02:03 GMT"
TimeShift.getTime(); // Get overridden values
1328230923000
TimeShift.getTimezoneOffset();
0
TimeShift.setTime(undefined); // Reset to current time
new Date().toString();
"Fri Aug 09 2013 20:37:45 GMT"
new Date().desc(); // Helper method
"utc=Fri, 09 Aug 2013 20:37:46 GMT local=Fri, 09 Aug 2013 20:37:46 GMT offset=0"
new TimeShift.OriginalDate().toString(); // Use original Date object
"Fri Aug 09 2013 23:37:47 GMT+0300 (EEST)"
```
Time zones
----------
TimeShift.js always utilizes its internal time zone offset when converting between local time and UTC. The offset factor is fixed, and it does not take into account DST changes. Effectively it emulates a time zone with no DST.
```javascript
new Date(1370034000000).toString(); // Original Date object uses variable offset
"Sat Jun 01 2013 00:00:00 GMT+0300 (EEST)"
new Date(1356991200000).toString();
"Tue Jan 01 2013 00:00:00 GMT+0200 (EET)"
Date = TimeShift.Date; // TimeShift.js uses fixed offset
new Date(1370034000000).toString();
"Sat Jun 01 2013 00:00:00 GMT+0300"
new Date(1356991200000).toString();
"Tue Jan 01 2013 01:00:00 GMT+0300"
```
The default time zone offset is the current local time zone offset. Note that this can change depending on local DST. Setting the time zone offset affects also previously created Date instances.
The time zone offset has the same sign as [Date.getTimezoneOffset](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset). For example, -120 is GMT+0200 and +120 is GMT-0200.
Caveats
-------
The mock implementation of Date is not perfect.
* Many string-generation methods are incomplete and return something indicative, but not fully correct. In particular `toDateString`, `toLocaleDateString`, `toLocaleString`, `toLocaleTimeString`, `toTimeString` produce somewhat incorrect results.
* The `toString` method does not contain any time zone name.
* The `parse` method delegates directly to the original method and may not handle time zones correctly.
* DST changes cannot be emulated. The time zone offset it always fixed.
* If a library or other code holds an original Date object or a reference to the Date prototype, things may break (e.g. error messages like "this is not a Date object"). In this case you should overwrite the Date object before loading the library.
If you'd like to fix some of these issues, please fork the repository, implement the desired functionality, add unit tests to `tests.js` and send a pull request.
License
-------
TimeShift.js is Copyright 2013 Mobile Wellness Solutions MWS Ltd and Sampo Niskanen.
It is released under the MIT license.

84
third_party/timeshift-js/package.json vendored Normal file
View file

@ -0,0 +1,84 @@
{
"_args": [
[
{
"raw": "timeshift-js@^1.0.0",
"scope": null,
"escapedName": "timeshift-js",
"name": "timeshift-js",
"rawSpec": "^1.0.0",
"spec": ">=1.0.0 <2.0.0",
"type": "range"
},
"/Users/martijn/Documents/Pebble/pebblesdk-generator/basalt/applib-targets/emscripten"
]
],
"_from": "timeshift-js@>=1.0.0 <2.0.0",
"_id": "timeshift-js@1.0.0",
"_inCache": true,
"_installable": true,
"_location": "/timeshift-js",
"_nodeVersion": "5.3.0",
"_npmUser": {
"name": "plaa",
"email": "sampo.niskanen@iki.fi"
},
"_npmVersion": "3.3.12",
"_phantomChildren": {},
"_requested": {
"raw": "timeshift-js@^1.0.0",
"scope": null,
"escapedName": "timeshift-js",
"name": "timeshift-js",
"rawSpec": "^1.0.0",
"spec": ">=1.0.0 <2.0.0",
"type": "range"
},
"_requiredBy": [
"/"
],
"_resolved": "https://registry.npmjs.org/timeshift-js/-/timeshift-js-1.0.0.tgz",
"_shasum": "61c2eebc12e9dabc81e5f99bbae2dc8d14593f70",
"_shrinkwrap": null,
"_spec": "timeshift-js@^1.0.0",
"_where": "/Users/martijn/Documents/Pebble/pebblesdk-generator/basalt/applib-targets/emscripten",
"author": {
"name": "Sampo Niskanen",
"email": "sampo.niskanen@iki.fi"
},
"bugs": {
"url": "https://github.com/plaa/TimeShift-js/issues"
},
"dependencies": {},
"description": "Time and timezone mocking / overriding",
"devDependencies": {},
"directories": {},
"dist": {
"shasum": "61c2eebc12e9dabc81e5f99bbae2dc8d14593f70",
"tarball": "https://registry.npmjs.org/timeshift-js/-/timeshift-js-1.0.0.tgz"
},
"gitHead": "2b0ae910e28ebbe40482c13ba48dc5c54adfe2b7",
"homepage": "https://github.com/plaa/TimeShift-js",
"keywords": [
"time",
"timezone",
"mocking"
],
"license": "MIT",
"main": "timeshift.js",
"maintainers": [
{
"name": "plaa",
"email": "sampo.niskanen@iki.fi"
}
],
"name": "timeshift-js",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/plaa/TimeShift-js.git"
},
"scripts": {},
"version": "1.0.0"
}

View file

@ -0,0 +1,244 @@
/**
* QUnit v1.12.0 - A JavaScript Unit Testing Framework
*
* http://qunitjs.com
*
* Copyright 2012 jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*/
/** Font Family and Sizes */
#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
}
#qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
#qunit-tests { font-size: smaller; }
/** Resets */
#qunit-tests, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter {
margin: 0;
padding: 0;
}
/** Header */
#qunit-header {
padding: 0.5em 0 0.5em 1em;
color: #8699a4;
background-color: #0d3349;
font-size: 1.5em;
line-height: 1em;
font-weight: normal;
border-radius: 5px 5px 0 0;
-moz-border-radius: 5px 5px 0 0;
-webkit-border-top-right-radius: 5px;
-webkit-border-top-left-radius: 5px;
}
#qunit-header a {
text-decoration: none;
color: #c2ccd1;
}
#qunit-header a:hover,
#qunit-header a:focus {
color: #fff;
}
#qunit-testrunner-toolbar label {
display: inline-block;
padding: 0 .5em 0 .1em;
}
#qunit-banner {
height: 5px;
}
#qunit-testrunner-toolbar {
padding: 0.5em 0 0.5em 2em;
color: #5E740B;
background-color: #eee;
overflow: hidden;
}
#qunit-userAgent {
padding: 0.5em 0 0.5em 2.5em;
background-color: #2b81af;
color: #fff;
text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
}
#qunit-modulefilter-container {
float: right;
}
/** Tests: Pass/Fail */
#qunit-tests {
list-style-position: inside;
}
#qunit-tests li {
padding: 0.4em 0.5em 0.4em 2.5em;
border-bottom: 1px solid #fff;
list-style-position: inside;
}
#qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running {
display: none;
}
#qunit-tests li strong {
cursor: pointer;
}
#qunit-tests li a {
padding: 0.5em;
color: #c2ccd1;
text-decoration: none;
}
#qunit-tests li a:hover,
#qunit-tests li a:focus {
color: #000;
}
#qunit-tests li .runtime {
float: right;
font-size: smaller;
}
.qunit-assert-list {
margin-top: 0.5em;
padding: 0.5em;
background-color: #fff;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}
.qunit-collapsed {
display: none;
}
#qunit-tests table {
border-collapse: collapse;
margin-top: .2em;
}
#qunit-tests th {
text-align: right;
vertical-align: top;
padding: 0 .5em 0 0;
}
#qunit-tests td {
vertical-align: top;
}
#qunit-tests pre {
margin: 0;
white-space: pre-wrap;
word-wrap: break-word;
}
#qunit-tests del {
background-color: #e0f2be;
color: #374e0c;
text-decoration: none;
}
#qunit-tests ins {
background-color: #ffcaca;
color: #500;
text-decoration: none;
}
/*** Test Counts */
#qunit-tests b.counts { color: black; }
#qunit-tests b.passed { color: #5E740B; }
#qunit-tests b.failed { color: #710909; }
#qunit-tests li li {
padding: 5px;
background-color: #fff;
border-bottom: none;
list-style-position: inside;
}
/*** Passing Styles */
#qunit-tests li li.pass {
color: #3c510c;
background-color: #fff;
border-left: 10px solid #C6E746;
}
#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
#qunit-tests .pass .test-name { color: #366097; }
#qunit-tests .pass .test-actual,
#qunit-tests .pass .test-expected { color: #999999; }
#qunit-banner.qunit-pass { background-color: #C6E746; }
/*** Failing Styles */
#qunit-tests li li.fail {
color: #710909;
background-color: #fff;
border-left: 10px solid #EE5757;
white-space: pre;
}
#qunit-tests > li:last-child {
border-radius: 0 0 5px 5px;
-moz-border-radius: 0 0 5px 5px;
-webkit-border-bottom-right-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
}
#qunit-tests .fail { color: #000000; background-color: #EE5757; }
#qunit-tests .fail .test-name,
#qunit-tests .fail .module-name { color: #000000; }
#qunit-tests .fail .test-actual { color: #EE5757; }
#qunit-tests .fail .test-expected { color: green; }
#qunit-banner.qunit-fail { background-color: #EE5757; }
/** Result */
#qunit-testresult {
padding: 0.5em 0.5em 0.5em 2.5em;
color: #2b81af;
background-color: #D2E0E6;
border-bottom: 1px solid white;
}
#qunit-testresult .module-name {
font-weight: bold;
}
/** Fixture */
#qunit-fixture {
position: absolute;
top: -10000px;
left: -10000px;
width: 1000px;
height: 1000px;
}

File diff suppressed because it is too large Load diff

15
third_party/timeshift-js/tests.html vendored Normal file
View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>TimeShift.js unit tests</title>
<link rel="stylesheet" href="qunit/qunit-1.12.0.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="timeshift.js"></script>
<script src="qunit/qunit-1.12.0.js"></script>
<script src="tests.js"></script>
</body>
</html>

520
third_party/timeshift-js/tests.js vendored Normal file
View file

@ -0,0 +1,520 @@
var JAN = 0;
var FEB = 1;
var MAR = 2;
var APR = 3;
var MAY = 4;
var JUN = 5;
var JUL = 6;
var AUG = 7;
var SEP = 8;
var OCT = 9;
var NOV = 10;
var DEC = 11;
var SUN = 0;
var MON = 1;
var TUE = 2;
var WED = 3;
var THU = 4;
var FRI = 5;
var SAT = 6;
function matches(d, year, month, day, hour, min, sec, msec, wkday) {
equal(d.getFullYear(), year, "year");
equal(d.getMonth(), month, "month");
equal(d.getDate(), day, "day of month");
equal(d.getHours(), hour, "hour");
equal(d.getMinutes(), min, "minutes");
equal(d.getSeconds(), sec, "seconds");
equal(d.getMilliseconds(), msec, "milliseconds");
equal(d.getDay(), wkday, "weekday");
equal(d.getYear(), year-1900, "year-1900");
}
function matchesUTC(d, year, month, day, hour, min, sec, msec, wkday) {
equal(d.getUTCFullYear(), year, "UTC year");
equal(d.getUTCMonth(), month, "UTC month");
equal(d.getUTCDate(), day, "UTC day of month");
equal(d.getUTCHours(), hour, "UTC hour");
equal(d.getUTCMinutes(), min, "UTC minutes");
equal(d.getUTCSeconds(), sec, "UTC seconds");
equal(d.getUTCMilliseconds(), msec, "UTC milliseconds");
equal(d.getUTCDay(), wkday, "UTC weekday");
}
////////////////// Constructor tests ///////////////////
test("no-arg constructor; no time set", function() {
TimeShift.setTimezoneOffset(-120);
var now = new Date();
var d = new TimeShift.Date();
ok(now.getTime() - d.getTime() < 500);
});
test("no-arg constructor; time set", function() {
TimeShift.setTimezoneOffset(-120);
TimeShift.setTime(1375991584123); // Thu 2013-08-08 19:53:04.123 UTC
var d = new TimeShift.Date();
matches(d, 2013, AUG, 8, 21, 53, 4, 123, THU);
matchesUTC(d, 2013, AUG, 8, 19, 53, 4, 123, THU);
TimeShift.setTime(undefined);
});
test("no-arg constructor; reset to normal time", function() {
TimeShift.setTimezoneOffset(-120);
TimeShift.setTime(1375991584123); // Thu 2013-08-08 19:53:04.123 UTC
TimeShift.setTime(undefined);
var now = new Date();
var d = new TimeShift.Date();
ok(now.getTime() - d.getTime() < 500);
});
test("timestamp constructor", function() {
TimeShift.setTimezoneOffset(-120);
var d = new TimeShift.Date(1375991584123); // Thu 2013-08-08 19:53:04.123 UTC
matches(d, 2013, AUG, 8, 21, 53, 4, 123, THU);
matchesUTC(d, 2013, AUG, 8, 19, 53, 4, 123, THU);
});
test("constructor year-month", function() {
TimeShift.setTimezoneOffset(180);
var d = new TimeShift.Date(2012, MAR); // Thu 2012-03-01 00:00:00 -0300
matches(d, 2012, MAR, 1, 00, 00, 00, 000, THU);
matchesUTC(d, 2012, MAR, 1, 03, 00, 00, 000, THU);
});
test("constructor year-month-day", function() {
TimeShift.setTimezoneOffset(-180);
var d = new TimeShift.Date(2012, MAR, 5); // Mon 2012-03-05 00:00:00 +0300
matches(d, 2012, MAR, 5, 00, 00, 00, 000, MON);
matchesUTC(d, 2012, MAR, 4, 21, 00, 00, 000, SUN);
});
test("constructor year-month-day-hour", function() {
TimeShift.setTimezoneOffset(-180);
var d = new TimeShift.Date(2012, MAR, 5, 23); // Mon 2012-03-05 23:00:00 +0300
matches(d, 2012, MAR, 5, 23, 00, 00, 000, MON);
matchesUTC(d, 2012, MAR, 5, 20, 00, 00, 000, MON);
});
test("constructor year-month-day-hour-min", function() {
TimeShift.setTimezoneOffset(-180);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45); // Mon 2012-03-05 23:45:00 +0300
matches(d, 2012, MAR, 5, 23, 45, 00, 000, MON);
matchesUTC(d, 2012, MAR, 5, 20, 45, 00, 000, MON);
});
test("constructor year-month-day-hour-min-sec", function() {
TimeShift.setTimezoneOffset(-180);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0300
matches(d, 2012, MAR, 5, 23, 45, 12, 000, MON);
matchesUTC(d, 2012, MAR, 5, 20, 45, 12, 000, MON);
});
test("constructor year-month-day-hour-min-sec-msec", function() {
TimeShift.setTimezoneOffset(-180);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12, 23); // Mon 2012-03-05 23:45:12.023 +0300
matches(d, 2012, MAR, 5, 23, 45, 12, 23, MON);
matchesUTC(d, 2012, MAR, 5, 20, 45, 12, 23, MON);
});
test("constructor year-month with timezone shift over month border", function() {
TimeShift.setTimezoneOffset(-120);
var d = new TimeShift.Date(2012, MAR); // Thu 2012-03-01 00:00:00 +0200
matches(d, 2012, MAR, 1, 00, 00, 00, 000, THU);
matchesUTC(d, 2012, FEB, 29, 22, 00, 00, 000, WED);
});
test("timezone shift over year boundary", function() {
TimeShift.setTimezoneOffset(-630);
var d = new TimeShift.Date(1356989624234); // Mon 2012-12-31 21:33:44.234 UTC
matches(d, 2013, JAN, 1, 8, 03, 44, 234, TUE);
matchesUTC(d, 2012, DEC, 31, 21, 33, 44, 234, MON);
});
/////////////////// Setter tests /////////////////////
test("set test precondition", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
matches(d, 2012, MAR, 5, 23, 45, 12, 000, MON);
matchesUTC(d, 2012, MAR, 5, 18, 45, 12, 000, MON);
});
//// Local time
test("setFullYear(year)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setFullYear(2011);
matches(d, 2011, MAR, 5, 23, 45, 12, 000, SAT);
matchesUTC(d, 2011, MAR, 5, 18, 45, 12, 000, SAT);
});
test("setFullYear(year, month)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setFullYear(2011, APR);
matches(d, 2011, APR, 5, 23, 45, 12, 000, TUE);
matchesUTC(d, 2011, APR, 5, 18, 45, 12, 000, TUE);
});
test("setFullYear(year, month, day)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setFullYear(2011, APR, 7);
matches(d, 2011, APR, 7, 23, 45, 12, 000, THU);
matchesUTC(d, 2011, APR, 7, 18, 45, 12, 000, THU);
});
test("setYear(year)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setYear(111);
matches(d, 2011, MAR, 5, 23, 45, 12, 000, SAT);
matchesUTC(d, 2011, MAR, 5, 18, 45, 12, 000, SAT);
});
test("setMonth(month)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setMonth(APR);
matches(d, 2012, APR, 5, 23, 45, 12, 000, THU);
matchesUTC(d, 2012, APR, 5, 18, 45, 12, 000, THU);
});
test("setMonth(month, day)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setMonth(APR, 7);
matches(d, 2012, APR, 7, 23, 45, 12, 000, SAT);
matchesUTC(d, 2012, APR, 7, 18, 45, 12, 000, SAT);
});
test("setDate(day)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setDate(7);
matches(d, 2012, MAR, 7, 23, 45, 12, 000, WED);
matchesUTC(d, 2012, MAR, 7, 18, 45, 12, 000, WED);
});
test("setHours(hour)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setHours(20);
matches(d, 2012, MAR, 5, 20, 45, 12, 000, MON);
matchesUTC(d, 2012, MAR, 5, 15, 45, 12, 000, MON);
});
test("setHours(hour, min)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setHours(20, 51);
matches(d, 2012, MAR, 5, 20, 51, 12, 000, MON);
matchesUTC(d, 2012, MAR, 5, 15, 51, 12, 000, MON);
});
test("setHours(hour, min, sec)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setHours(20, 51, 22);
matches(d, 2012, MAR, 5, 20, 51, 22, 000, MON);
matchesUTC(d, 2012, MAR, 5, 15, 51, 22, 000, MON);
});
test("setHours(hour, min, sec, msec)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setHours(20, 51, 22, 123);
matches(d, 2012, MAR, 5, 20, 51, 22, 123, MON);
matchesUTC(d, 2012, MAR, 5, 15, 51, 22, 123, MON);
});
test("setMinutes(min)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setMinutes(52);
matches(d, 2012, MAR, 5, 23, 52, 12, 000, MON);
matchesUTC(d, 2012, MAR, 5, 18, 52, 12, 000, MON);
});
test("setMinutes(min, sec)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setMinutes(52, 22);
matches(d, 2012, MAR, 5, 23, 52, 22, 000, MON);
matchesUTC(d, 2012, MAR, 5, 18, 52, 22, 000, MON);
});
test("setMinutes(min, sec, msec)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setMinutes(52, 22, 123);
matches(d, 2012, MAR, 5, 23, 52, 22, 123, MON);
matchesUTC(d, 2012, MAR, 5, 18, 52, 22, 123, MON);
});
test("setSeconds(sec)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setSeconds(22);
matches(d, 2012, MAR, 5, 23, 45, 22, 000, MON);
matchesUTC(d, 2012, MAR, 5, 18, 45, 22, 000, MON);
});
test("setSeconds(sec, msec)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setSeconds(22, 123);
matches(d, 2012, MAR, 5, 23, 45, 22, 123, MON);
matchesUTC(d, 2012, MAR, 5, 18, 45, 22, 123, MON);
});
test("setMilliseconds(msec)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setMilliseconds(123);
matches(d, 2012, MAR, 5, 23, 45, 12, 123, MON);
matchesUTC(d, 2012, MAR, 5, 18, 45, 12, 123, MON);
});
//// UTC time
test("setUTCFullYear(year)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setUTCFullYear(2011);
matches(d, 2011, MAR, 5, 23, 45, 12, 000, SAT);
matchesUTC(d, 2011, MAR, 5, 18, 45, 12, 000, SAT);
});
test("setUTCFullYear(year, month)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setUTCFullYear(2011, APR);
matches(d, 2011, APR, 5, 23, 45, 12, 000, TUE);
matchesUTC(d, 2011, APR, 5, 18, 45, 12, 000, TUE);
});
test("setUTCFullYear(year, month, day)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setUTCFullYear(2011, APR, 7);
matches(d, 2011, APR, 7, 23, 45, 12, 000, THU);
matchesUTC(d, 2011, APR, 7, 18, 45, 12, 000, THU);
});
test("setUTCMonth(month)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setUTCMonth(APR);
matches(d, 2012, APR, 5, 23, 45, 12, 000, THU);
matchesUTC(d, 2012, APR, 5, 18, 45, 12, 000, THU);
});
test("setUTCMonth(month, day)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setUTCMonth(APR, 7);
matches(d, 2012, APR, 7, 23, 45, 12, 000, SAT);
matchesUTC(d, 2012, APR, 7, 18, 45, 12, 000, SAT);
});
test("setUTCDate(day)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setUTCDate(7);
matches(d, 2012, MAR, 7, 23, 45, 12, 000, WED);
matchesUTC(d, 2012, MAR, 7, 18, 45, 12, 000, WED);
});
test("setUTCHours(hour)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setUTCHours(10);
matches(d, 2012, MAR, 5, 15, 45, 12, 000, MON);
matchesUTC(d, 2012, MAR, 5, 10, 45, 12, 000, MON);
});
test("setUTCHours(hour, min)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setUTCHours(10, 51);
matches(d, 2012, MAR, 5, 15, 51, 12, 000, MON);
matchesUTC(d, 2012, MAR, 5, 10, 51, 12, 000, MON);
});
test("setUTCHours(hour, min, sec)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setUTCHours(10, 51, 22);
matches(d, 2012, MAR, 5, 15, 51, 22, 000, MON);
matchesUTC(d, 2012, MAR, 5, 10, 51, 22, 000, MON);
});
test("setUTCHours(hour, min, sec, msec)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setUTCHours(10, 51, 22, 123);
matches(d, 2012, MAR, 5, 15, 51, 22, 123, MON);
matchesUTC(d, 2012, MAR, 5, 10, 51, 22, 123, MON);
});
test("setUTCMinutes(min)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setUTCMinutes(52);
matches(d, 2012, MAR, 5, 23, 52, 12, 000, MON);
matchesUTC(d, 2012, MAR, 5, 18, 52, 12, 000, MON);
});
test("setUTCMinutes(min, sec)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setUTCMinutes(52, 22);
matches(d, 2012, MAR, 5, 23, 52, 22, 000, MON);
matchesUTC(d, 2012, MAR, 5, 18, 52, 22, 000, MON);
});
test("setUTCMinutes(min, sec, msec)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setUTCMinutes(52, 22, 123);
matches(d, 2012, MAR, 5, 23, 52, 22, 123, MON);
matchesUTC(d, 2012, MAR, 5, 18, 52, 22, 123, MON);
});
test("setUTCSeconds(sec)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setUTCSeconds(22);
matches(d, 2012, MAR, 5, 23, 45, 22, 000, MON);
matchesUTC(d, 2012, MAR, 5, 18, 45, 22, 000, MON);
});
test("setUTCSeconds(sec, msec)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setUTCSeconds(22, 123);
matches(d, 2012, MAR, 5, 23, 45, 22, 123, MON);
matchesUTC(d, 2012, MAR, 5, 18, 45, 22, 123, MON);
});
test("setUTCMilliseconds(msec)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setUTCMilliseconds(123);
matches(d, 2012, MAR, 5, 23, 45, 12, 123, MON);
matchesUTC(d, 2012, MAR, 5, 18, 45, 12, 123, MON);
});
//// Other setters
test("setTime(time)", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12); // Mon 2012-03-05 23:45:12 +0500
d.setTime(1375991584123); // Thu 2013-08-08 19:53:04.123 UTC
matches(d, 2013, AUG, 9, 00, 53, 04, 123, FRI);
matchesUTC(d, 2013, AUG, 8, 19, 53, 04, 123, THU);
});
//////////////////// Other functionality ////////////////////
test("getTime(), valueOf()", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12, 123); // Mon 2012-03-05 23:45:12.123 +0500
equal(d.getTime(), 1330973112123);
equal(d.valueOf(), 1330973112123);
});
test("getTimezoneOffset()", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12, 123); // Mon 2012-03-05 23:45:12.123 +0500
equal(d.getTimezoneOffset(), -300);
TimeShift.setTimezoneOffset(-650);
equal(d.getTimezoneOffset(), -650);
TimeShift.setTimezoneOffset(550);
equal(d.getTimezoneOffset(), 550);
});
///////////////////// "Class" functions ////////////////////
test("Date.now(); no time set", function() {
TimeShift.setTimezoneOffset(-120);
var now = Date.now();
var t = TimeShift.Date.now();
ok(now - t < 500);
});
test("Date.now(); time set", function() {
TimeShift.setTimezoneOffset(-120);
TimeShift.setTime(1375991584123); // Thu 2013-08-08 19:53:04.123 UTC
var t = TimeShift.Date.now();
equal(t, 1375991584123);
TimeShift.setTime(undefined);
});
test("Date.now(); reset to normal time", function() {
TimeShift.setTimezoneOffset(-120);
TimeShift.setTime(1375991584123); // Thu 2013-08-08 19:53:04.123 UTC
TimeShift.setTime(undefined);
var now = Date.now();
var t = TimeShift.Date.now();
ok(now - t < 500);
});
test("Date.UTC", function() {
TimeShift.setTimezoneOffset(-120);
var t = TimeShift.Date.UTC(2012, MAR, 5, 23, 45, 12, 123); // Mon 2012-03-05 23:45:12 UTC
equal(t, 1330991112123);
});
// Date.parse is probably not correct
///////////////////// String functions (approximate) /////////////////////
test("toString()", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 6, 7, 8, 123); // Mon 2012-03-05 06:07:08.123 +0500
equal(d.toString(), "Mon Mar 05 2012 06:07:08 GMT+0500");
});
test("toString() 2", function() {
TimeShift.setTimezoneOffset(300);
var d = new TimeShift.Date(2012, DEC, 29, 6, 7, 8, 123); // Sat 2012-12-29 06:07:08.123 -0500
equal(d.toString(), "Sat Dec 29 2012 06:07:08 GMT-0500");
});
test("toString() 3", function() {
TimeShift.setTimezoneOffset(0);
var d = new TimeShift.Date(2012, JAN, 1, 6, 7, 8, 123); // Sun 2012-01-01 06:07:08.123 GMT
equal(d.toString(), "Sun Jan 01 2012 06:07:08 GMT");
});
test("toUTCString()", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12, 123); // Mon 2012-03-05 23:45:12.123 +0500
// IE has slightly own format
ok(d.toUTCString().match(/^Mon, 0?5 Mar 2012 18:45:12 (GMT|UTC)$/));
});
test("toISOString()", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12, 123); // Mon 2012-03-05 23:45:12.123 +0500
equal(d.toISOString(), "2012-03-05T18:45:12.123Z");
});
test("toJSON()", function() {
TimeShift.setTimezoneOffset(-300);
var d = new TimeShift.Date(2012, MAR, 5, 23, 45, 12, 123); // Mon 2012-03-05 23:45:12.123 +0500
equal(d.toJSON(), "2012-03-05T18:45:12.123Z");
});

244
third_party/timeshift-js/timeshift.js vendored Normal file
View file

@ -0,0 +1,244 @@
/*!
* TimeShift.js version 20130811
*
* Copyright 2013 Mobile Wellness Solutions MWS Ltd, Sampo Niskanen
* Released under the MIT license
*/
// Add to Rocky.Module:
Module.TimeShift = (function(originalDate) {
var OriginalDate = originalDate;
var TimeShift = {};
var currentTime = undefined;
var timezoneOffset = new OriginalDate().getTimezoneOffset();
function currentDate() {
if (currentTime) {
return new OriginalDate(currentTime);
} else {
return new OriginalDate();
}
}
function realLocalToUtc(realLocal) {
return new OriginalDate(realLocal.getTime() - realLocal.getTimezoneOffset()*60*1000 + timezoneOffset*60*1000);
}
function utcToLocal(utc) {
return new OriginalDate(utc.getTime() - timezoneOffset*60*1000);
}
function localToUtc(local) {
return new OriginalDate(local.getTime() + timezoneOffset*60*1000);
}
function twoDigit(n) {
if (n < 10) {
return "0" + n;
} else {
return "" + n;
}
}
function timezoneName() {
var zone = "GMT";
var offset = Math.abs(timezoneOffset);
if (timezoneOffset < 0) {
zone = zone + "+";
} else if (timezoneOffset > 0) {
zone = zone + "-";
} else {
return zone;
}
return zone + twoDigit(Math.floor(offset/60)) + twoDigit(offset%60);
}
/**
* Return the current time zone offset in minutes. A value of -60 corresponds to GMT+1,
* +60 to GTM-1. Default value is from new Date().getTimezoneOffset().
*/
TimeShift.getTimezoneOffset = function() {
return timezoneOffset;
}
/**
* Set the time zone offset in minutes. -60 corresponds to GMT+1, +60 to GTM-1.
* Changing this will affect the results also for previously created Date instances.
*/
TimeShift.setTimezoneOffset = function(offset) {
timezoneOffset = offset;
}
/**
* Return the currently overridden time value as milliseconds after Jan 1 1970 in UTC time.
* The default value is undefined, which indicates using the real current time.
*/
TimeShift.getTime = function() {
return currentTime;
}
/**
* Set the current time in milliseconds after Jan 1 1970 in UTC time. Setting this
* to undefined will reset to the real current time.
*/
TimeShift.setTime = function(time) {
currentTime = time;
}
/**
* Access to the original Date constructor.
*/
TimeShift.OriginalDate = OriginalDate;
/**
* Mock implementation of Date.
*/
TimeShift.Date = function() {
// Detect whether we're being called with 'new'
// From http://stackoverflow.com/questions/367768/how-to-detect-if-a-function-is-called-as-constructor
var isConstructor = false;
if (this instanceof TimeShift.Date && !this.__previouslyConstructedByTimeShift) {
isConstructor = true;
this.__previouslyConstructedByTimeShift = true;
}
if (!isConstructor) {
return (new TimeShift.Date()).toString();
}
switch (arguments.length) {
case 0:
this.utc = currentDate();
break;
case 1:
this.utc = new OriginalDate(arguments[0]);
break;
case 2:
this.utc = realLocalToUtc(new OriginalDate(arguments[0], arguments[1]));
break;
case 3:
this.utc = realLocalToUtc(new OriginalDate(arguments[0], arguments[1], arguments[2]));
break;
case 4:
this.utc = realLocalToUtc(new OriginalDate(arguments[0], arguments[1], arguments[2], arguments[3]));
break;
case 5:
this.utc = realLocalToUtc(new OriginalDate(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]));
break;
case 6:
this.utc = realLocalToUtc(new OriginalDate(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]));
break;
default:
this.utc = realLocalToUtc(new OriginalDate(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6]));
break;
}
}
TimeShift.Date.prototype.getDate = function() { return utcToLocal(this.utc).getUTCDate(); }
TimeShift.Date.prototype.getDay = function() { return utcToLocal(this.utc).getUTCDay(); }
TimeShift.Date.prototype.getFullYear = function() { return utcToLocal(this.utc).getUTCFullYear(); }
TimeShift.Date.prototype.getHours = function() { return utcToLocal(this.utc).getUTCHours(); }
TimeShift.Date.prototype.getMilliseconds = function() { return utcToLocal(this.utc).getUTCMilliseconds(); }
TimeShift.Date.prototype.getMinutes = function() { return utcToLocal(this.utc).getUTCMinutes(); }
TimeShift.Date.prototype.getMonth = function() { return utcToLocal(this.utc).getUTCMonth(); }
TimeShift.Date.prototype.getSeconds = function() { return utcToLocal(this.utc).getUTCSeconds(); }
TimeShift.Date.prototype.getUTCDate = function() { return this.utc.getUTCDate(); }
TimeShift.Date.prototype.getUTCDay = function() { return this.utc.getUTCDay(); }
TimeShift.Date.prototype.getUTCFullYear = function() { return this.utc.getUTCFullYear(); }
TimeShift.Date.prototype.getUTCHours = function() { return this.utc.getUTCHours(); }
TimeShift.Date.prototype.getUTCMilliseconds = function() { return this.utc.getUTCMilliseconds(); }
TimeShift.Date.prototype.getUTCMinutes = function() { return this.utc.getUTCMinutes(); }
TimeShift.Date.prototype.getUTCMonth = function() { return this.utc.getUTCMonth(); }
TimeShift.Date.prototype.getUTCSeconds = function() { return this.utc.getUTCSeconds(); }
TimeShift.Date.prototype.setDate = function() { var d = utcToLocal(this.utc); d.setUTCDate.apply(d, Array.prototype.slice.call(arguments, 0)); this.utc = localToUtc(d); }
TimeShift.Date.prototype.setFullYear = function() { var d = utcToLocal(this.utc); d.setUTCFullYear.apply(d, Array.prototype.slice.call(arguments, 0)); this.utc = localToUtc(d); }
TimeShift.Date.prototype.setHours = function() { var d = utcToLocal(this.utc); d.setUTCHours.apply(d, Array.prototype.slice.call(arguments, 0)); this.utc = localToUtc(d); }
TimeShift.Date.prototype.setMilliseconds = function() { var d = utcToLocal(this.utc); d.setUTCMilliseconds.apply(d, Array.prototype.slice.call(arguments, 0)); this.utc = localToUtc(d); }
TimeShift.Date.prototype.setMinutes = function() { var d = utcToLocal(this.utc); d.setUTCMinutes.apply(d, Array.prototype.slice.call(arguments, 0)); this.utc = localToUtc(d); }
TimeShift.Date.prototype.setMonth = function() { var d = utcToLocal(this.utc); d.setUTCMonth.apply(d, Array.prototype.slice.call(arguments, 0)); this.utc = localToUtc(d); }
TimeShift.Date.prototype.setSeconds = function() { var d = utcToLocal(this.utc); d.setUTCSeconds.apply(d, Array.prototype.slice.call(arguments, 0)); this.utc = localToUtc(d); }
TimeShift.Date.prototype.setUTCDate = function() { this.utc.setUTCDate.apply(this.utc, Array.prototype.slice.call(arguments, 0)); }
TimeShift.Date.prototype.setUTCFullYear = function() { this.utc.setUTCFullYear.apply(this.utc, Array.prototype.slice.call(arguments, 0)); }
TimeShift.Date.prototype.setUTCHours = function() { this.utc.setUTCHours.apply(this.utc, Array.prototype.slice.call(arguments, 0)); }
TimeShift.Date.prototype.setUTCMilliseconds = function() { this.utc.setUTCMilliseconds.apply(this.utc, Array.prototype.slice.call(arguments, 0)); }
TimeShift.Date.prototype.setUTCMinutes = function() { this.utc.setUTCMinutes.apply(this.utc, Array.prototype.slice.call(arguments, 0)); }
TimeShift.Date.prototype.setUTCMonth = function() { this.utc.setUTCMonth.apply(this.utc, Array.prototype.slice.call(arguments, 0)); }
TimeShift.Date.prototype.setUTCSeconds = function() { this.utc.setUTCSeconds.apply(this.utc, Array.prototype.slice.call(arguments, 0)); }
TimeShift.Date.prototype.getYear = function() { return this.getFullYear() - 1900; }
TimeShift.Date.prototype.setYear = function(v) { this.setFullYear(v + 1900); }
TimeShift.Date.prototype.getTime = function() { return this.utc.getTime(); }
TimeShift.Date.prototype.setTime = function(v) { this.utc.setTime(v); }
TimeShift.Date.prototype.getTimezoneOffset = function() { return timezoneOffset; }
TimeShift.Date.prototype.toDateString = function() { return utcToLocal(this.utc).toDateString(); } // Wrong
// Added to Date.prototype by rocky_api_datetime.c:
// TimeShift.Date.prototype.toLocaleDateString = function() { return utcToLocal(this.utc).toLocaleDateString(); } // Wrong
TimeShift.Date.prototype.toISOString = function() { return this.utc.toISOString(); }
TimeShift.Date.prototype.toGMTString = function() { return this.utc.toGMTString(); }
TimeShift.Date.prototype.toUTCString = function() { return this.utc.toUTCString(); }
TimeShift.Date.prototype.toString = function() {
var wkdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var d = utcToLocal(this.utc);
// Mon Mar 05 2012 06:07:08 GMT+0500
return wkdays[d.getUTCDay()] + " " + months[d.getUTCMonth()] + " " + twoDigit(d.getUTCDate()) + " " + d.getUTCFullYear() +
" " + twoDigit(d.getUTCHours()) + ":" + twoDigit(d.getUTCMinutes()) + ":" + twoDigit(d.getUTCSeconds()) + " " + timezoneName();
}
// Added to Date.prototype by rocky_api_datetime.c:
// TimeShift.Date.prototype.toLocaleString = function() { return this.toString(); } // Wrong
// TimeShift.Date.prototype.toLocaleTimeString = function() { return this.toString(); } // Wrong
TimeShift.Date.prototype.toTimeString = function() { return this.toString(); } // Wrong
TimeShift.Date.prototype.toJSON = function() { return this.utc.toJSON(); }
TimeShift.Date.prototype.valueOf = function() { return this.utc.getTime(); }
TimeShift.Date.now = function() { return currentDate().getTime(); }
TimeShift.Date.parse = OriginalDate.parse; // Wrong
TimeShift.Date.UTC = OriginalDate.UTC;
/**
* Helper method that describes a Date object contents.
*/
TimeShift.Date.prototype.desc = function() {
return "utc=" + this.utc.toUTCString() + " local=" + utcToLocal(this.utc).toUTCString() + " offset=" + timezoneOffset;
}
return TimeShift;
})(Date);
// Replace original Date:
Date = Module.TimeShift.Date;
var callTickTimerServiceHandleTimeChange = function() {
Module.ccall('tick_timer_service_handle_time_change');
}
Module.setTime = function(time) {
Module.TimeShift.setTime(time);
callTickTimerServiceHandleTimeChange();
}
Module.setTimezoneOffset = function(offset) {
Module.TimeShift.setTimezoneOffset(offset);
callTickTimerServiceHandleTimeChange();
}
Module.set24hStyle = function(is_24h_style) {
Module.ccall('clock_set_24h_style', null, ['number'], [is_24h_style]);
callTickTimerServiceHandleTimeChange();
}