mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-17 02:05:22 -04:00
fix: monthly schedule label shows 21th/22th/31th (ordinal suffix for days >20) (#1577)
This commit is contained in:
+2
-1
@@ -7,6 +7,7 @@ import markdownModule from './markdown.js';
|
||||
import * as spinnerModule from './spinner.js';
|
||||
import { makeWindowDraggable } from './windowDrag.js';
|
||||
import { sortModelIds } from './modelSort.js';
|
||||
import { ordinalSuffix } from './util/ordinal.js';
|
||||
|
||||
const API_BASE = window.location.origin;
|
||||
let _open = false;
|
||||
@@ -244,7 +245,7 @@ function _scheduleLabel(task) {
|
||||
}
|
||||
if (task.schedule === 'monthly') {
|
||||
const d = task.scheduled_day ?? 1;
|
||||
const suffix = d === 1 ? 'st' : d === 2 ? 'nd' : d === 3 ? 'rd' : 'th';
|
||||
const suffix = ordinalSuffix(d);
|
||||
return `Monthly on ${d}${suffix} at ${localTime}`;
|
||||
}
|
||||
return task.schedule || '—';
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// Pure (browser-free) English ordinal suffix, e.g. 1 -> "st", 21 -> "st",
|
||||
// 22 -> "nd", 23 -> "rd", 11/12/13 -> "th". Extracted so it can be unit-tested.
|
||||
export function ordinalSuffix(n) {
|
||||
const a = Math.abs(Math.trunc(Number(n) || 0));
|
||||
const mod100 = a % 100;
|
||||
if (mod100 >= 11 && mod100 <= 13) return 'th';
|
||||
switch (a % 10) {
|
||||
case 1: return 'st';
|
||||
case 2: return 'nd';
|
||||
case 3: return 'rd';
|
||||
default: return 'th';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user