Files
gerrit/polygerrit-ui/app/test/gr-date-formatter-test.html
Andrew Bonventre 3f33f6735e Fix bug where 12:NN PM was being displaed as 0:NN PM
Change-Id: I941a8146fba3c85610e99bd70cd7a766d59700f2
2016-01-27 12:59:10 -05:00

85 lines
2.6 KiB
HTML

<!DOCTYPE html>
<!--
Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>gr-date-formatter</title>
<script src="../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../bower_components/web-component-tester/browser.js"></script>
<script src="../scripts/util.js"></script>
<link rel="import" href="../elements/gr-date-formatter.html">
<test-fixture id="basic">
<template>
<gr-date-formatter date-str="2015-09-24 23:30:17.033000000"></gr-date-formatter>
</template>
</test-fixture>
<script>
suite('gr-date-formatter tests', function() {
var element;
setup(function() {
element = fixture('basic');
});
test('date is parsed correctly', function() {
assert.notOk((new Date('foo')).valueOf());
var d = element._parseDateStr(element.getAttribute('date-str'));
assert.isAbove(d.valueOf(), 0);
});
function normalizedDate(dateStr) {
var d = new Date(dateStr);
d.setMinutes(d.getMinutes() + d.getTimezoneOffset());
return d;
}
function testDates(nowStr, dateStr, expected) {
var now = normalizedDate(nowStr);
var t = normalizedDate(dateStr);
assert.equal(element._dateStr(t, now), expected);
}
test('dates strings are correct', function() {
// Within 24 hours on same day.
testDates('2015-07-29T20:34:00.000Z',
'2015-07-29T15:34:00.000Z',
'3:34 PM');
testDates('2016-01-27T17:41:00.000Z',
'2016-01-27T12:41:00.000Z',
'12:41 PM');
// Within 24 hours on different days.
testDates('2015-07-29T03:34:00.000Z',
'2015-07-28T20:25:00.000Z',
'Jul 28');
// More than 24 hours. Less than six months.
testDates('2015-07-29T20:34:00.000Z',
'2015-06-15T03:25:00.000Z',
'Jun 15');
// More than six months.
testDates('2015-09-15T20:34:00.000Z',
'2015-01-15T03:25:00.000Z',
'Jan 15, 2015');
});
});
</script>