aboutsummaryrefslogtreecommitdiff
path: root/src/lib.ts
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2022-12-26 15:51:20 +1100
committerTerry Truong <terry06890@gmail.com>2022-12-26 15:51:20 +1100
commit1c76bf712516fb69db63e1433c1cec8a00f48f74 (patch)
tree2faf28e0c8b53c95baa02d372f32bbadd9cd8d98 /src/lib.ts
parente4f1e98e9312a73474ff582ae8dc43cfb93b359a (diff)
Make minor ticks more evenly spread
Fix getNumDisplayUnits() not account for lack of 0 CE Add getNumSubUnits() in lib.ts
Diffstat (limited to 'src/lib.ts')
-rw-r--r--src/lib.ts13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/lib.ts b/src/lib.ts
index 8cbd937..fdabe4b 100644
--- a/src/lib.ts
+++ b/src/lib.ts
@@ -451,6 +451,19 @@ export function getScaleRatio(scale: number, scale2: number, lowerVal=false){
}
return scale2 / scale;
}
+export function getNumSubUnits(date: HistDate, scaleIdx: number){
+ // Returns number of sub-units for a unit starting at 'date' on scale for 'scaleIdx'
+ const scale = SCALES[scaleIdx]
+ if (scale == DAY_SCALE){
+ throw new Error('Cannot get sub-units for DAY_SCALE unit');
+ } else if (scale == MONTH_SCALE){
+ return getDaysInMonth(date.year, date.month); // Note: Intentionally not checking with MIN_CAL_YEAR
+ } else if (scale == 1){
+ return 12;
+ } else {
+ return scale / SCALES[scaleIdx + 1] - (date.year == 1 ? 1 : 0); // Account for lack of 0 CE
+ }
+}
export function getUnitDiff(date: HistDate, date2: HistDate, scale: number): number {
if (scale == DAY_SCALE){
return date.getDayDiff(date2);