aboutsummaryrefslogtreecommitdiff
path: root/src/lib.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.ts')
-rw-r--r--src/lib.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/lib.ts b/src/lib.ts
index f6147dc..d26c8df 100644
--- a/src/lib.ts
+++ b/src/lib.ts
@@ -565,6 +565,21 @@ export function dateToUnit(date: HistDate, scale: number): number {
}
}
}
+export function dateToScaleDate(date: HistDate, scale: number): HistDate {
+ // Returns a date representing the unit on 'scale' that 'date' is within
+ if (scale == DAY_SCALE){
+ return new CalDate(date.year, date.month, date.day);
+ } else if (scale == MONTH_SCALE){
+ return new CalDate(date.year, date.month, 1);
+ } else {
+ const year = Math.floor(date.year / scale) * scale;
+ if (year < MIN_CAL_YEAR){
+ return new YearDate(year);
+ } else {
+ return new CalDate(year == 0 ? 1 : year, 1, 1);
+ }
+ }
+}
// For sending timeline-bound data to BaseLine
export class TimelineState {