On Wed, 18 Feb 2009, Timothy S. Nelson wrote: > I'll try and design an API that does what DateTime does, but:
> 1. Uses more variables, of which I expect the getters and setters to be > overridden. Please let's NOT have setters on "time" objects. They're a source of subtle bugs in such client code AND having mutable objects means you can't use them in otherwise pure code. (See the separate thread on immutability and purity.) Rather, let's have immutable time "values", and methods which return other "values" where various computations (*1) have been applied. Provide constructors which take the Y/M/D/h/m/s/dst_now/dst_rule tuple. And please let's not have any implied "default" timezone. That's not to say it has to be difficult or cumbersome, just explicit, perhaps something like one of these: my &localtime = DateTime::Gregorian.localize( :host_default ); my &localtime = DateTime::Gregorian.localize( :user_env ); my &localtime = DateTime::Gregorian.localize( :http_client(%http_client_headers) ); my &localtime = DateTime::Gregorian.localize( :db_server($odbc_handle) ); my &gmtime = DateTime::Gregorian.localize( :utc ); my &swatch = DateTime::Gregorian.localize( :tz('Europe/Geneva'), :no_dst ); -Martin *1: Operations on localtime objects involve differences, offsets and baselines, expressed in a range of units. The core units are seconds, minutes and days which are almost-but-not-quite exact multiples of each other (consider leap seconds (*2) and daylight saving). It is up to the client code to choose whether to treat an "hour" offset as exactly 1/24 day or as exactly 60 minutes. If you want a sunrise-based local time then that's a different library entirely. In the Gregorian and Julian calendars a "year" is an exact multiple of a "month", which is not an exact multiple of any core unit. A true astronomical calendar will take a "lunar month" to be ~2.551E6 seconds and a "solar year" to be ~3.1557E7 seconds; a tabular calendar will need them to be yet more separate offset types, and a separate library. *2: Or not, if you're on a POSIX host, in which case you sometimes get a peculiar "second" that takes twice as long as most, while a "minute" is always and precisely 60 "seconds".