-
Notifications
You must be signed in to change notification settings - Fork 39
Open
Description
run the following code on a computer set to US Eastern locale and get 9999-12-30 instead of the desired 12-31.
import ae.utils.time.types;
import ae.utils.time.parse;
import core.time : nsecs, days;
import std.string;
import std.algorithm;
import std.conv;
import std.exception;
import std.datetime;
void main() {
AbsTime t;
import std.stdio;
writeln(timestamp("9999-12-31 00:00:00").date);
}
private Date date(AbsTime time) => cast(Date)time.sysTime;
private AbsTime timestamp(string s) {
// PostgreSQL optionally outputs a second fraction, if it is non-zero
auto parts = s.findSplit(".");
AbsTime result = parts[0].parseAbsTime!"Y-m-d H:i:s";
if (parts) {
enforce(parts[2].length <= 9, "Too much precision");
result += nsecs(parts[2].to!int * 10 ^^ (9 - parts[2].length));
}
return result;
}
Metadata
Metadata
Assignees
Labels
No labels