Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isoDateTime() and isoTime() don't use milliseconds which causes issues for uptime-kuma push notifications #6

Closed
kaysond opened this issue Apr 4, 2022 · 0 comments · Fixed by #7

Comments

@kaysond
Copy link
Contributor

kaysond commented Apr 4, 2022

See louislam/uptime-kuma#1422 and louislam/uptime-kuma#1428

Without milliseconds in the format, the time information in the database can't be used to determine intervals <1 second. For example, if you have one event at 12:15:24.999 and another at 12:15:45.001, the database will record them as 12:15:24 and 12:15:45, showing a 21s time difference even though its much closer to 20s (20.002).

I think the best way to fix this is to add isoDateTimeMilliseconds() and isoTimeMilliseconds(), copying these functions

isoDateTime(dateTime : dayjs.Dayjs | Date | undefined = undefined) : string {
let dayjsObject;
if (dateTime instanceof dayjs) {
dayjsObject = dateTime;
} else {
dayjsObject = dayjs(dateTime);
}
return dayjsObject.format('YYYY-MM-DD HH:mm:ss');
}

isoTime(date : dayjs.Dayjs | Date | undefined = undefined) {
let dayjsObject;
if (date instanceof dayjs) {
dayjsObject = date;
} else {
dayjsObject = dayjs(date);
}
return dayjsObject.format('HH:mm:ss');
}

isDateTime(value : string) {
let format = "YYYY-MM-DD HH:mm:ss";
return dayjs(value, format).format(format) === value;
}

isTime(value : string) {
// Since dayjs is not supporting time only format, so prefix a fake date to parse
value = "2020-10-20 " + value;
let format = "YYYY-MM-DD HH:mm:ss";
return dayjs(value, format).format(format) === value;
}

We'd also need to update getDataType()

getDataType(value, fieldName : string = "") {

and isValidType()

isValidType(columnType, valueType) {

I may be missing some functions, particularly as far as the underlying db column type. I'm pretty sure mariadb supports milliseconds in datetime, and I believe sqlite just stores it as text so it should work no problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant