diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-10-15 11:39:56 +1100 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-10-15 11:39:56 +1100 |
| commit | 37c4267ff74ce75d3de5c00a2e9febfc21c00a33 (patch) | |
| tree | 36ad55d84e15163293420c4b6882829215c643b2 /src/lib.ts | |
| parent | 4a0ffc55734adaaf3e9eacd9ee4bbc212e96a71e (diff) | |
On zooming out, align dates with start of units (eg: 1970-1-1 not 1970-2-4)
Make getMovedBounds() non-globals-dependent
Diffstat (limited to 'src/lib.ts')
| -rw-r--r-- | src/lib.ts | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -7,7 +7,12 @@ export const WRITING_MODE_HORZ = window.getComputedStyle(document.body)['writing-mode' as any].startsWith('horizontal'); // Used with ResizeObserver callbacks, to determine which resized dimensions are width and height -// For calendar conversion. Same as in backend/hist_data/cal.py +// Similar to %, but for negative LHS, return a positive offset from a lower RHS multiple +export function moduloPositive(x: number, y: number){ + return x - Math.floor(x / y) * y; +} + +// For calendar conversion. Mostly copied from backend/hist_data/cal.py export function gregorianToJdn(year: number, month: number, day: number): number { if (year < 0){ year += 1; @@ -61,6 +66,9 @@ export function julianToGregorian(year: number, month: number, day: number): [nu export function gregorianToJulian(year: number, month: number, day: number): [number, number, number] { return jdnToJulian(gregorianToJdn(year, month, day)); } +export function getDaysInMonth(year: number, month: number){ + return gregorianToJdn(year, month + 1, 1) - gregorianToJdn(year, month, 1); +} // For date representation export class HistDate { |
