walltime-js
Version:
A javascript library for easily translating a UTC time to a "Wall Time" for a particular time zone and back.
71 lines (57 loc) • 2.49 kB
HTML
<html>
<head>
<meta charset="utf-8">
<title>Walltime RequireJS Test</title>
<link rel="stylesheet" href="mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script type="text/javascript" src="require.js"></script>
<script type="text/javascript" src="../../client/walltime-data.js"></script>
<script>
require.config({
paths: {
walltime: "../../client/walltime"
},
shim: {
mocha: {
exports: 'mocha'
}
}
});
require(["chai", "mocha", "walltime"], function (chai, mocha, WallTime) {
var should = chai.should(),
// Apollo 11 was the spaceflight that landed the first humans on the Moon,
// Americans Neil Armstrong and Buzz Aldrin, on July 20, 1969, at 20:18 UTC.
landingTime = Date.UTC(1969, 6, 20, 20, 18, 0, 0);
mocha.setup('bdd');
describe("WallTime - RequireJS", function () {
it("exists", function () {
should.exist(WallTime);
should.exist(WallTime.init);
});
it("can convert Apollo 11 landing time for America/Chicago", function () {
var chicagoLandingTime = WallTime.UTCToWallTime(landingTime, "America/Chicago");
should.exist(chicagoLandingTime);
chicagoLandingTime.getFullYear().should.equal(1969);
chicagoLandingTime.getMonth().should.equal(6);
chicagoLandingTime.getDate().should.equal(20);
chicagoLandingTime.getHours().should.equal(15);
chicagoLandingTime.getMinutes().should.equal(18);
});
it("can convert Jul 26 2013, 6:50 AM", function () {
var chicagoTime = WallTime.UTCToWallTime(1374839400000, "America/Chicago");
chicagoTime.getFullYear().should.equal(2013);
chicagoTime.getMonth().should.equal(6);
chicagoTime.getDate().should.equal(26);
chicagoTime.getHours().should.equal(6);
chicagoTime.getMinutes().should.equal(50);
});
});
if (window.mochaPhantomJS) mochaPhantomJS.run()
else mocha.run();
});
</script>
</body>
</html>