Hi,
I'm trying to understand the correct use of the std/times library. Specifically I'd like to know the intended use of the DateTime vs Time.
A DateTime has all extractors and can be converted to a Time, while a Time has no extractors, but the arithmetic and comparison operations particularly with a Duration are much faster as mentioned in the documentation. Behind the format(Time): string => parse(string): DateTime there is no simple way to convert a DateTime to a Time. It seems that once you use a Time there is no simple way to extract components or convert it to a DateTime, only format(Time) output routine is available.
For your convenience I provide below brief outline of the supported operations by the DateTime and Time types.
# DateTime = time parts
# - now(), dateTime() constructors
# - [nanosecond..year] extractors
# - toTime() DateTime => Time convertor
# - parse() + format()
# Time = seconds + nanoseconds
# - getTime(), initTime() constructors
# - NO extractors
# - toUnix(), fromUnix() convertors
# - parseTime() + format()
# Arithmetic: DateTime/Time +/- Duration/TimeInterval
# Comparison: DateTime/Time </<=/== DateTime/Time
As I understand it, the main differences between DateTime and Time are support for timezones and relative efficiencies in addition/subtraction compared to extracting date and time components. If you need to support multiple time zones or expect to issue more calls to extract components than addition/subtractions, choose DateTime, otherwise choose Time.
For conversion from Time to DateTime, you have local(dt:DateTime) and utc(dt:DateTime).