mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Improve natural unit conversion for a time b/w 360 to 365 days (#3901)
* Improve natural unit conversion for a time b/w 360 to 365 days Previously, 363 days would be converted to 12.1 months, which is quite confusing because - a user would think that if the value is more than 12 months, why it isn't displayed in years - the value is actually less than a year, which is counterintuitive as 12.1 m suggests a value more than a year. * precise * Update time.ts to match timespan.rs * Add another test * Use average duration of a month instead * Update time.ts * Update test_schedv3.py * Update time.test.ts
This commit is contained in:
parent
332830e5d7
commit
e546c6d11f
4 changed files with 9 additions and 5 deletions
|
@ -537,7 +537,7 @@ def test_nextIvl():
|
|||
assert ni(c, 3) == 21600000
|
||||
# (* 100 2.5 1.3 86400)28080000.0
|
||||
assert ni(c, 4) == 28080000
|
||||
assert without_unicode_isolation(col.sched.nextIvlStr(c, 4)) == "10.8mo"
|
||||
assert without_unicode_isolation(col.sched.nextIvlStr(c, 4)) == "10.7mo"
|
||||
|
||||
|
||||
def test_bury():
|
||||
|
|
|
@ -57,7 +57,7 @@ const SECOND: f32 = 1.0;
|
|||
const MINUTE: f32 = 60.0 * SECOND;
|
||||
const HOUR: f32 = 60.0 * MINUTE;
|
||||
const DAY: f32 = 24.0 * HOUR;
|
||||
const MONTH: f32 = 30.0 * DAY;
|
||||
const MONTH: f32 = 30.417 * DAY; // 365/12 ≈ 30.417
|
||||
const YEAR: f32 = 365.0 * DAY;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
|
@ -188,6 +188,10 @@ mod test {
|
|||
assert_eq!(time_span(30.3, &tr, true), "30.3 seconds");
|
||||
assert_eq!(time_span(90.0, &tr, false), "1.5 minutes");
|
||||
assert_eq!(time_span(45.0 * 86_400.0, &tr, false), "1.5 months");
|
||||
assert_eq!(time_span(364.0 * 86_400.0, &tr, false), "12 months");
|
||||
assert_eq!(time_span(364.0 * 86_400.0, &tr, true), "11.97 months");
|
||||
assert_eq!(time_span(365.0 * 86_400.0, &tr, false), "1 year");
|
||||
assert_eq!(time_span(365.0 * 86_400.0, &tr, true), "1 year");
|
||||
assert_eq!(time_span(365.0 * 86_400.0 * 1.5, &tr, false), "1.5 years");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ test("natural unit", () => {
|
|||
expect(naturalUnit(60 * 60 - 1)).toBe(TimespanUnit.Minutes);
|
||||
expect(naturalUnit(60 * 60)).toBe(TimespanUnit.Hours);
|
||||
expect(naturalUnit(60 * 60 * 24)).toBe(TimespanUnit.Days);
|
||||
expect(naturalUnit(60 * 60 * 24 * 30)).toBe(TimespanUnit.Months);
|
||||
expect(naturalUnit(60 * 60 * 24 * 31)).toBe(TimespanUnit.Months);
|
||||
});
|
||||
|
||||
test("natural whole unit", () => {
|
||||
|
|
|
@ -7,8 +7,8 @@ export const SECOND = 1.0;
|
|||
export const MINUTE = 60.0 * SECOND;
|
||||
export const HOUR = 60.0 * MINUTE;
|
||||
export const DAY = 24.0 * HOUR;
|
||||
export const MONTH = 30.0 * DAY;
|
||||
export const YEAR = 12.0 * MONTH;
|
||||
export const MONTH = 30.417 * DAY; // 365/12 ≈ 30.417
|
||||
export const YEAR = 365.0 * DAY;
|
||||
|
||||
export enum TimespanUnit {
|
||||
Seconds,
|
||||
|
|
Loading…
Reference in a new issue