• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wanasit / chrono / 16856517969

10 Aug 2025 02:56AM UTC coverage: 90.789% (+0.02%) from 90.768%
16856517969

push

github

google-labs-jules[bot]
Refactor: Replace deprecated dayjs functions with native Date

This commit continues the refactoring effort to remove the `dayjs` library from the codebase.

It replaces `dayjs` objects and their methods with native JavaScript `Date` objects and corresponding date manipulation logic. Specifically, it updates numerous locale-specific parsers and common utility files to use new helper functions that operate on `Date` objects (e.g., `assignSimilarDate` from `utils/dates.ts`) instead of the deprecated `dayjs`-based helpers.

The deprecated functions in `src/utils/dayjs.ts` have been removed.

1673 of 2121 branches covered (78.88%)

78 of 87 new or added lines in 12 files covered. (89.66%)

2 existing lines in 2 files now uncovered.

4948 of 5450 relevant lines covered (90.79%)

387.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.83
/src/calculation/mergingCalculation.ts
1
import { ParsingComponents, ParsingResult } from "../results";
2
import { Meridiem } from "../types";
96✔
3
import { assignSimilarDate, implySimilarDate } from "../utils/dates";
96✔
4

5
export function mergeDateTimeResult(dateResult: ParsingResult, timeResult: ParsingResult): ParsingResult {
96✔
6
    const result = dateResult.clone();
264✔
7
    const beginDate = dateResult.start;
264✔
8
    const beginTime = timeResult.start;
264✔
9

10
    result.start = mergeDateTimeComponent(beginDate, beginTime);
264✔
11
    if (dateResult.end != null || timeResult.end != null) {
264✔
12
        const endDate = dateResult.end == null ? dateResult.start : dateResult.end;
43✔
13
        const endTime = timeResult.end == null ? timeResult.start : timeResult.end;
43✔
14
        const endDateTime = mergeDateTimeComponent(endDate, endTime);
43✔
15

16
        if (dateResult.end == null && endDateTime.date().getTime() < result.start.date().getTime()) {
43✔
17
            // For example,  "Tuesday 9pm - 1am" the ending should actually be 1am on the next day.
18
            // We need to add to ending by another day.
19
            const nextDay = new Date(endDateTime.date().getTime());
3✔
20
            nextDay.setDate(nextDay.getDate() + 1);
3✔
21
            if (endDateTime.isCertain("day")) {
3!
22
                assignSimilarDate(endDateTime, nextDay);
3✔
23
            } else {
NEW
24
                implySimilarDate(endDateTime, nextDay);
×
25
            }
26
        }
27

28
        result.end = endDateTime;
43✔
29
    }
30

31
    return result;
264✔
32
}
33

34
export function mergeDateTimeComponent(
96✔
35
    dateComponent: ParsingComponents,
36
    timeComponent: ParsingComponents
37
): ParsingComponents {
38
    const dateTimeComponent = dateComponent.clone();
307✔
39

40
    if (timeComponent.isCertain("hour")) {
307✔
41
        dateTimeComponent.assign("hour", timeComponent.get("hour"));
286✔
42
        dateTimeComponent.assign("minute", timeComponent.get("minute"));
286✔
43

44
        if (timeComponent.isCertain("second")) {
286✔
45
            dateTimeComponent.assign("second", timeComponent.get("second"));
29✔
46

47
            if (timeComponent.isCertain("millisecond")) {
29✔
48
                dateTimeComponent.assign("millisecond", timeComponent.get("millisecond"));
1✔
49
            } else {
50
                dateTimeComponent.imply("millisecond", timeComponent.get("millisecond"));
28✔
51
            }
52
        } else {
53
            dateTimeComponent.imply("second", timeComponent.get("second"));
257✔
54
            dateTimeComponent.imply("millisecond", timeComponent.get("millisecond"));
257✔
55
        }
56
    } else {
57
        dateTimeComponent.imply("hour", timeComponent.get("hour"));
21✔
58
        dateTimeComponent.imply("minute", timeComponent.get("minute"));
21✔
59
        dateTimeComponent.imply("second", timeComponent.get("second"));
21✔
60
        dateTimeComponent.imply("millisecond", timeComponent.get("millisecond"));
21✔
61
    }
62

63
    if (timeComponent.isCertain("timezoneOffset")) {
307✔
64
        dateTimeComponent.assign("timezoneOffset", timeComponent.get("timezoneOffset"));
20✔
65
    }
66

67
    if (timeComponent.isCertain("meridiem")) {
307✔
68
        dateTimeComponent.assign("meridiem", timeComponent.get("meridiem"));
201✔
69
    } else if (timeComponent.get("meridiem") != null && dateTimeComponent.get("meridiem") == null) {
106✔
70
        dateTimeComponent.imply("meridiem", timeComponent.get("meridiem"));
85✔
71
    }
72

73
    if (dateTimeComponent.get("meridiem") == Meridiem.PM && dateTimeComponent.get("hour") < 12) {
307✔
74
        if (timeComponent.isCertain("hour")) {
13!
75
            dateTimeComponent.assign("hour", dateTimeComponent.get("hour") + 12);
13✔
76
        } else {
77
            dateTimeComponent.imply("hour", dateTimeComponent.get("hour") + 12);
×
78
        }
79
    }
80

81
    dateTimeComponent.addTags(dateComponent.tags());
307✔
82
    dateTimeComponent.addTags(timeComponent.tags());
307✔
83
    return dateTimeComponent;
307✔
84
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc