@minnowdb/core 0.6.9 → 0.7.0

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.
@@ -13,3 +13,8 @@ export declare function dateUtcMinutes(value: Date): number;
13
13
  export declare function dateUtcSeconds(value: Date): number;
14
14
  export declare function setDateUtcDate(value: Date, day: number): number;
15
15
  export declare function setDateUtcMonth(value: Date, month: number): number;
16
+ /** Whole days since 1970-01-01 for an epoch-millisecond value (floored, so negatives work). */
17
+ export declare function epochDays(milliseconds: number): number;
18
+ export declare function civilFromDays(days: number): readonly [number, number, number];
19
+ /** Days since 1970-01-01 for a civil date; month is 0-11 as in Date.UTC. */
20
+ export declare function daysFromCivil(year: number, month: number, day: number): number;
@@ -62,3 +62,44 @@ export function setDateUtcDate(value, day) {
62
62
  export function setDateUtcMonth(value, month) {
63
63
  return intrinsicDateSetUtcMonth.call(value, month);
64
64
  }
65
+ const MS_PER_DAY = 86_400_000;
66
+ /** Whole days since 1970-01-01 for an epoch-millisecond value (floored, so negatives work). */
67
+ export function epochDays(milliseconds) {
68
+ return Math.floor(milliseconds / MS_PER_DAY);
69
+ }
70
+ /**
71
+ * Proleptic Gregorian civil date for a day count since 1970-01-01, without a Date allocation
72
+ * (Howard Hinnant's days-to-civil algorithm). Returns [year, month (0-11), day (1-31)] in a
73
+ * shared scratch array: callers read it before the next call.
74
+ */
75
+ const civilScratch = [0, 0, 0];
76
+ export function civilFromDays(days) {
77
+ const z = days + 719_468;
78
+ const era = Math.floor(z / 146_097);
79
+ const dayOfEra = z - era * 146_097;
80
+ const yearOfEra = (dayOfEra -
81
+ Math.floor(dayOfEra / 1460) +
82
+ Math.floor(dayOfEra / 36_524) -
83
+ Math.floor(dayOfEra / 146_096)) /
84
+ 365;
85
+ const yoe = Math.floor(yearOfEra);
86
+ const dayOfYear = dayOfEra - (365 * yoe + Math.floor(yoe / 4) - Math.floor(yoe / 100));
87
+ const mp = Math.floor((5 * dayOfYear + 2) / 153);
88
+ const day = dayOfYear - Math.floor((153 * mp + 2) / 5) + 1;
89
+ const month = mp < 10 ? mp + 2 : mp - 10;
90
+ const year = yoe + era * 400 + (month <= 1 ? 1 : 0);
91
+ civilScratch[0] = year;
92
+ civilScratch[1] = month;
93
+ civilScratch[2] = day;
94
+ return civilScratch;
95
+ }
96
+ /** Days since 1970-01-01 for a civil date; month is 0-11 as in Date.UTC. */
97
+ export function daysFromCivil(year, month, day) {
98
+ const y = month <= 1 ? year - 1 : year;
99
+ const era = Math.floor(y / 400);
100
+ const yoe = y - era * 400;
101
+ const mp = month > 1 ? month - 2 : month + 10;
102
+ const dayOfYear = Math.floor((153 * mp + 2) / 5) + day - 1;
103
+ const dayOfEra = yoe * 365 + Math.floor(yoe / 4) - Math.floor(yoe / 100) + dayOfYear;
104
+ return era * 146_097 + dayOfEra - 719_468;
105
+ }