Skip to content

Commit 9254fe8

Browse files
authored
Add private API for knowing if time should be used (#50)
When parsing the natural language text like 'today', you get back a full NSDate with a time set at 12:00. Previously to understand this case I would remove the time if it was noon, which also broke you manually specifying '12:00'. It turns out there's a private API for this instead, so this now safely calls that, warning if it breaks. This at least works on macOS 13 but based on class dumps I think it has been around since at least 2018. Fixes #33
1 parent 348f5da commit 9254fe8

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Sources/RemindersLibrary/NaturalLanguage.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,20 @@ private func components(from string: String) -> DateComponents? {
2828
return nil
2929
}
3030

31+
var includeTime = true
32+
if match.responds(to: NSSelectorFromString("timeIsSignificant")) {
33+
includeTime = match.value(forKey: "timeIsSignificant") as? Bool ?? true
34+
} else {
35+
print("warning: timeIsSignificant is not available, please report this to keith/reminders-cli")
36+
}
37+
3138
let timeZone = match.timeZone ?? .current
3239
let parsedComponents = calendar.dateComponents(in: timeZone, from: date)
33-
if let noon = calendar.date(bySettingHour: 12, minute: 0, second: 0, of: date),
34-
calendar.compare(date, to: noon, toGranularity: .minute) == .orderedSame
35-
{
40+
if includeTime {
41+
return parsedComponents
42+
} else {
3643
return calendar.dateComponents(calendarComponents(except: timeComponents), from: date)
3744
}
38-
39-
return parsedComponents
4045
}
4146

4247
extension DateComponents: ExpressibleByArgument {

0 commit comments

Comments
 (0)