Debian Codegraph @

tests/moment-timezone/pack-base-60.js

raw symbols SCIP
1 "use strict";
2
3 var tz = require("../../moment-timezone-utils").tz;
4
5 function compare(test, data) {
6 var i,
7 input,
8 output,
9 expected,
10 precision;
11
12 for (i = 0; i < data.length; i++) {
13 input = data[i][0];
14 precision = data[i][1];
15 expected = data[i][2];
16 output = tz.packBase60(input, precision);
17 test.equal(output, expected, 'packing ' + input + ' to ' + precision + ' decimal places should equal ' + expected);
18 }
19
20 test.done();
21 }
22
23 exports['pack-base-60'] = {
24 ints : function (test) {
25 compare(test, [
26 [0, 0, '0'],
27 [1, 0, '1'],
28 [9, 0, '9'],
29 [10, 0, 'a'],
30 [35, 0, 'z'],
31 [36, 0, 'A'],
32 [59, 0, 'X'],
33 [60, 0, '10'],
34 [60 + 1, 0, '11'],
35 [60 + 10, 0, '1a'],
36 [60 + 35, 0, '1z'],
37 [60 + 36, 0, '1A'],
38 [60 + 59, 0, '1X'],
39 [60 * 60, 0, '100'],
40 [2799360000000, 0, '10000000']
41 ]);
42 },
43
44 floats : function (test) {
45 compare(test, [
46 [0, 10, '0'],
47 [ 1 / 60, 1, '.1'],
48 [ 9 / 60, 1, '.9'],
49 [10 / 60, 1, '.a'],
50 [35 / 60, 1, '.z'],
51 [36 / 60, 1, '.A'],
52 [59 / 60, 1, '.X'],
53 [ 1 / 60, 2, '.1'],
54 [59 / 60, 2, '.X'],
55 [59 / 60, 6, '.X'],
56 [1 / 3600, 1, '0'],
57 [1 / 3600, 2, '.01'],
58 [(1 / 60) + ( 1 / 3600), 2, '.11'],
59 [(1 / 60) + (10 / 3600), 2, '.1a'],
60 [(1 / 60) + (35 / 3600), 2, '.1z'],
61 [(1 / 60) + (36 / 3600), 2, '.1A'],
62 [(1 / 60) + (59 / 3600), 2, '.1X'],
63 [(1 / 60) + ( 1 / 3600), 3, '.11'],
64 [(1 / 60) + (59 / 3600), 3, '.1X'],
65 [(1 / 60) + (59 / 3600), 8, '.1X'],
66 [1 / (60 * 60 * 60 * 60 * 60 * 60 * 60 * 60), 8, '.00000001']
67 ]);
68 },
69
70 negative : function (test) {
71 compare(test, [
72 [-0, 0, '0'],
73 [-1, 0, '-1'],
74 [-60, 0, '-10'],
75 [-(60 + 59), 0, '-1X'],
76 [ -1 / 60, 1, '-.1'],
77 [-35 / 60, 1, '-.z'],
78 [ -1 / 3600, 1, '0'],
79 [-((1 / 60) + (59 / 3600)), 8, '-.1X'],
80 [-1 / (60 * 60 * 60 * 60 * 60 * 60 * 60 * 60), 8, '-.00000001']
81 ]);
82 },
83 };