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

wanasit / chrono / 25412136268

06 May 2026 01:44AM UTC coverage: 92.859%. Remained the same
25412136268

push

github

Wanasit Tanakitrungruang
2.9.1

1927 of 2325 branches covered (82.88%)

5917 of 6372 relevant lines covered (92.86%)

460.43 hits per line

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

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

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

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

16
        if (dateResult.end == null && endDateTime.date().getTime() < result.start.date().getTime()) {
44✔
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 {
24
                implySimilarDate(endDateTime, nextDay);
×
25
            }
26
        }
27

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

31
    return result;
288✔
32
}
33

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

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

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

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

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

67
    const dateHasMeaningfulMeridiem =
68
        dateComponent.get("meridiem") != null &&
332✔
69
        (dateComponent.isCertain("meridiem") ||
70
            Array.from(dateComponent.tags()).some((t) => t.startsWith("casualReference/")));
27✔
71

72
    if (timeComponent.isCertain("meridiem")) {
332✔
73
        dateTimeComponent.assign("meridiem", timeComponent.get("meridiem"));
206✔
74
    } else if (timeComponent.get("meridiem") != null && !dateHasMeaningfulMeridiem) {
126✔
75
        // Let the time component guide meridiem only when the date part doesn't already carry a meaningful (certain or casual) hint.
76
        dateTimeComponent.imply("meridiem", timeComponent.get("meridiem"));
102✔
77
    }
78

79
    if (dateTimeComponent.get("meridiem") == Meridiem.PM && dateTimeComponent.get("hour") < 12) {
332✔
80
        if (timeComponent.isCertain("hour")) {
13!
81
            dateTimeComponent.assign("hour", dateTimeComponent.get("hour") + 12);
13✔
82
        } else {
83
            dateTimeComponent.imply("hour", dateTimeComponent.get("hour") + 12);
×
84
        }
85
    }
86

87
    dateTimeComponent.addTags(dateComponent.tags());
332✔
88
    dateTimeComponent.addTags(timeComponent.tags());
332✔
89
    return dateTimeComponent;
332✔
90
}
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