@miso.ai/server-commons 0.6.5-beta.17 → 0.6.5-beta.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -23,5 +23,5 @@
23
23
  "uuid": "^9.0.0",
24
24
  "yargs": "^17.5.1"
25
25
  },
26
- "version": "0.6.5-beta.17"
26
+ "version": "0.6.5-beta.18"
27
27
  }
package/src/date.js CHANGED
@@ -52,7 +52,8 @@ export function floorDate(expr, unit) {
52
52
  return undefined;
53
53
  }
54
54
  const [_unit, ts] = parseDateExpr(expr);
55
- if (unit === undefined || !isGranular(unit, _unit)) {
55
+ //console.error('floorDate', expr, unit, _unit, ts, unit === undefined || !isGranular(unit, _unit));
56
+ if (unit === undefined || isGranular(unit, _unit)) {
56
57
  return ts;
57
58
  }
58
59
  return floorTimestamp(ts, unit);
@@ -81,7 +82,7 @@ function floorTimestamp(ts, unit) {
81
82
  case 'month':
82
83
  return Date.UTC(year, month - 1);
83
84
  case 'quarter':
84
- return Date.UTC(year, month - month % 3 - 3);
85
+ return Date.UTC(year, month - 1 - (month - 1) % 3);
85
86
  case 'year':
86
87
  return Date.UTC(year);
87
88
  default:
package/test/date.test.js CHANGED
@@ -6,6 +6,10 @@ function testDateFn(fn, input, output) {
6
6
  assert.equal(new Date(fn(input)).toISOString(), output, `${fn.name}(${input})`);
7
7
  }
8
8
 
9
+ function testDateFnWithUnit(fn, input, unit, output) {
10
+ assert.equal(new Date(fn(input, unit)).toISOString(), output, `${fn.name}(${input}, ${unit})`);
11
+ }
12
+
9
13
  test('startOfDate', () => {
10
14
  testDateFn(startOfDate, '2025', '2025-01-01T00:00:00.000Z');
11
15
  testDateFn(startOfDate, '2025-Q1', '2025-01-01T00:00:00.000Z');
@@ -42,6 +46,13 @@ test('floorDate', () => {
42
46
  testDateFn(floorDate, '2025-02-W1', '2025-02-01T00:00:00.000Z');
43
47
  testDateFn(floorDate, '2025-02-w2', '2025-02-08T00:00:00.000Z');
44
48
  testDateFn(floorDate, '2025-02-03', '2025-02-03T00:00:00.000Z');
49
+
50
+ const ts = Date.parse('2025-05-10T04:05:06Z');
51
+ testDateFnWithUnit(floorDate, ts, 'day', '2025-05-10T00:00:00.000Z');
52
+ testDateFnWithUnit(floorDate, ts, 'week', '2025-05-08T00:00:00.000Z');
53
+ testDateFnWithUnit(floorDate, ts, 'month', '2025-05-01T00:00:00.000Z');
54
+ testDateFnWithUnit(floorDate, ts, 'quarter', '2025-04-01T00:00:00.000Z');
55
+ testDateFnWithUnit(floorDate, ts, 'year', '2025-01-01T00:00:00.000Z');
45
56
  });
46
57
 
47
58
  test('ceilDate', () => {
@@ -82,6 +93,19 @@ test('prevDate', () => {
82
93
  testDateFn(prevDate, '2025-02-W3', '2025-02-08T00:00:00.000Z');
83
94
  testDateFn(prevDate, '2025-02-w4', '2025-02-15T00:00:00.000Z');
84
95
  testDateFn(prevDate, '2025-02-03', '2025-02-02T00:00:00.000Z');
96
+
97
+ const ts = Date.parse('2025-05-10T04:05:06Z');
98
+ testDateFnWithUnit(prevDate, ts, 'day', '2025-05-10T00:00:00.000Z');
99
+ testDateFnWithUnit(prevDate, ts, 'week', '2025-05-08T00:00:00.000Z');
100
+ testDateFnWithUnit(prevDate, ts, 'month', '2025-05-01T00:00:00.000Z');
101
+ testDateFnWithUnit(prevDate, ts, 'quarter', '2025-04-01T00:00:00.000Z');
102
+ testDateFnWithUnit(prevDate, ts, 'year', '2025-01-01T00:00:00.000Z');
103
+
104
+ testDateFnWithUnit(prevDate, '2025', 'day', '2024-12-31T00:00:00.000Z');
105
+ testDateFnWithUnit(prevDate, '2025', 'week', '2024-12-22T00:00:00.000Z');
106
+ testDateFnWithUnit(prevDate, '2025', 'month', '2024-12-01T00:00:00.000Z');
107
+ testDateFnWithUnit(prevDate, '2025', 'quarter', '2024-10-01T00:00:00.000Z');
108
+
85
109
  });
86
110
 
87
111
  test.run();