Bug 14792 – Add function to convert from unix time to SysTime
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-07-09T22:51:00Z
Last change time
2015-10-04T18:20:03Z
Assigned to
nobody
Creator
issues.dlang
Comments
Comment #0 by issues.dlang — 2015-07-09T22:51:56Z
SysTime currently has toUnixTime to convert to unix time (which is what time_t usually is, though apparently, the C standard does not require it to be unix time, and in the case of dmc, it isn't). However, SysTime does not provide a way to convert from unix time to SysTime. We have stdTimeToUnixTime and unixTimeToStdTime to do the conversions of the integral values, but while toUnixTime wraps stdTimeToUnixTime for you, in the case of converting to from unix time, you currently have to do something like
auto st = SysTime(unixTimeToStdTime(myTimeT));
It's been requested on multiple occasions that we have a function like toUnixTime except that it does the conversion in the opposite direction, thus allowing for code like
auto st = SysTime.fromUnixTime(myTimeT);
Comment #1 by github-bugzilla — 2015-07-19T14:15:22Z
Commits pushed to master at https://github.com/D-Programming-Language/phoboshttps://github.com/D-Programming-Language/phobos/commit/4899aa85d22114cd56be87ec8cb243d2a13f5b1e
Implement issue# 14792: Add SysTime.fromUnixTime.
We've had the ability to convert from unix time to SysTime, but it has
been more unwieldy than it should be. This adds fromUnixTime to go with
toUnixTime.
In addition, these changes solve the problem where you sometimes need a
value for unix time that doesn't fit in time_t (e.g. a 64-bit value on a
32-bit system), or you're dealing with a 64-bit time_t on a 32-bit
system (which Windows sometimes does). So, toUnixTime and
stdTimeToUnixTime now take an optional template argument which indicates
how many bits the result should be (defaulting to match the size of
time_t), and fromUnixTime and unixTimeToStdTime now take long rather
than time_t so that they can accept 64-bit values on 32-bit systems.
https://github.com/D-Programming-Language/phobos/commit/a9cd76147fbb87e0326c3e302119a7eb0e531d6d
Merge pull request #3481 from jmdavis/issue14792
Implement issue# 14792: Add SysTime.fromUnixTime.
Comment #2 by github-bugzilla — 2015-10-04T18:20:03Z