Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
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
42
43
44
45
46
47
48
/* global describe, test, expect */
import { msToHMS, prettyDate } from "../date";
 
describe("Helper function prettyDate", () => {
  test("Undefined", () => {
    expect(prettyDate(undefined)).toBeUndefined();
    expect(prettyDate(null)).toBeUndefined();
    expect(prettyDate(123)).toBeUndefined();
  });
 
  test("Yesterday", () => {
    const today = new Date();
    const testing = new Date(Date.UTC(today.getFullYear(), today.getMonth(), today.getDate()));
    const resultDate = new Date(testing.setDate(testing.getDate() - 1));
 
    expect(prettyDate(resultDate.toISOString())).toBe("Yesterday");
  });
 
  test("2 days ago", () => {
    const today = new Date();
    const testing = new Date(Date.UTC(today.getFullYear(), today.getMonth(), today.getDate()));
    const resultDate = new Date(testing.setDate(testing.getDate() - 2));
 
    expect(prettyDate(resultDate.toISOString())).toBe("2 days ago");
  });
 
  test("2 weeks ago", () => {
    const today = new Date();
    const testing = new Date(Date.UTC(today.getFullYear(), today.getMonth(), today.getDate()));
    const resultDate = new Date(testing.setDate(testing.getDate() - 14));
 
    expect(prettyDate(resultDate.toISOString())).toBe("2 weeks ago");
  });
 
  test("100 days ago", () => {
    const today = new Date();
    const testing = new Date(Date.UTC(today.getFullYear(), today.getMonth(), today.getDate()));
    const resultDate = new Date(testing.setDate(testing.getDate() - 100));
 
    expect(prettyDate(resultDate.toISOString())).toBe("100 days ago");
  });
});
 
describe("Helper function msToHMS", () => {
  test("Correct", () => {
    expect(msToHMS(10000)).toBe("0:0:10");
  });
});