This repository was archived by the owner on Jan 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathpretty.js
More file actions
41 lines (39 loc) · 1.8 KB
/
pretty.js
File metadata and controls
41 lines (39 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* eslint-env node */
/* global QUnit */
var tk = require( "timekeeper" );
var prettyDate = require( "../js/pretty.js" ).prettyDate;
QUnit.module( "prettyDate", function ( hooks ) {
hooks.beforeEach( function () {
tk.freeze( "2011-04-01T00:00:00Z" );
} );
[
{ input: "", output: undefined },
{ input: "2010-04-01T00:00:00Z", output: undefined },
{ input: "2011-01-01T00:00:00Z", output: undefined },
{ input: "2011-02-01T00:00:00Z", output: undefined },
{ input: "2011-03-01T00:00:00Z", output: undefined },
{ input: "2011-03-10T00:00:00Z", output: "4 weeks ago" },
{ input: "2011-03-21T00:00:00Z", output: "2 weeks ago" },
{ input: "2011-03-22T00:00:00Z", output: "2 weeks ago" },
{ input: "2011-03-23T00:00:00Z", output: "2 weeks ago" },
{ input: "2011-03-24T00:00:00Z", output: "2 weeks ago" },
{ input: "2011-03-25T00:00:00Z", output: "1 week ago" },
{ input: "2011-03-26T00:00:00Z", output: "6 days ago" },
{ input: "2011-03-29T00:00:00Z", output: "3 days ago" },
{ input: "2011-03-30T00:00:00Z", output: "2 days ago" },
{ input: "2011-03-31T00:00:00Z", output: "Yesterday" },
{ input: "2011-03-31T10:00:00Z", output: "14 hours ago" },
{ input: "2011-03-31T22:00:00Z", output: "2 hours ago" },
{ input: "2011-03-31T23:00:00Z", output: "1 hour ago" },
{ input: "2011-03-31T23:30:00Z", output: "30 minutes ago" },
{ input: "2011-03-31T23:45:40Z", output: "14 minutes ago" },
{ input: "2011-03-31T23:59:00Z", output: "1 minute ago" },
{ input: "2011-03-31T23:59:30Z", output: "30 seconds ago" },
{ input: "2011-03-31T23:59:49Z", output: "11 seconds ago" },
{ input: "2011-03-31T23:59:55Z", output: "just now" }
].forEach( function ( val ) {
QUnit.test( JSON.stringify( val.input ), function ( assert ) {
assert.strictEqual( prettyDate( val.input ), val.output );
} );
} );
} );