Forum OpenACS Development: Timezones

Collapse
Posted by Lars Pind on
I'm trying to figure out what the best design is here. There are at least three different timezones in play.

1) Server OS timezone. I don't think we care about this.

2) OACS system timezone setting: The default timezone.

3) User preference: The timezone you're in.

The ACS Java design doc suggests that we store date/times in the DB in the OACS system timezone (2), and then convert to the user's local timezone as appropriate. I think that's a good plan.

My question is: Can the people the procs 'lc_time_utc_to_locale' and 'lc_time_local_to_utc' explain to me how they were supposed to be used?

What I'll need to do is to convert from OACS system timezone setting to user setting and back, so what I really need is 'lc_time_system_to_user' and 'lc_time_user_to_system' procs.

Were these procs designed with a different design in mind?

/Lars

Collapse
2: Re: Timezones (response to 1)
Posted by Eduardo Pérez on
date/times must always be stored in UTC in the DB, then they can be converted to whatever timezone the user wants.

Then the dates can be shown in the specified user's local timezone or in UTC if the user didn't specify a timezone or the local time (OACS system timezone setting) if the site is a one timezone only site.

So you don't need 'lc_time_system_to_user' and 'lc_time_user_to_system' because date/times must the in UTC in the DB

Collapse
3: Re: Timezones (response to 2)
Posted by Jeff Davis on
I guess it was Ash Katwala and I that inflicted those procs on the world.  One point is that I disagree with the ACS Java docs (and agree with Eduardo) that date/times should be UTC in the DB (although I also think the server should be on UTC as well so in some sense it is the same answer).  Unfortunately we rely on the DB datetime formatting all over the place
which means running everything as UTC and formatting on
output is problematic.

Anyway, those routines were the lowest level ones on which
something like lc_time_utc_to_user would be built.

Also, keep in mind that in some cases you want the time you
present to be something other than the users timezone.
An example would be a travel itenerary where the departure
times should be the local timezone for the airport.

Collapse
4: Re: Timezones (response to 1)
Posted by Jon Griffin on
I guess I am missing something here.

ref-timezones should have everything you need and I don't believe that date/times should always be stored in the DB,but if they are they should be stored in the server date setting (which IMHO should be UTC anyway).

I left AD before the java is god days so I don't know what went on then, but a good deal of time was spent in the LA office creating the timezone and datetime packages.

Again, I may be missing something obvious so ...

Collapse
5: Re: Timezones (response to 1)
Posted by Lars Pind on
Jon,

I don't think you're missing anything.

I'm just trying to figure out how to do this bastard thing, so I'm asking around.

I'm aware of the timezone package in ref-timezones, which is also what the procs I mentioned in acs-lang use. We want a Tcl API on top of that, though, and that's what the acs-lang procs provide. ref-timezones doesn't have any Tcl API.

The issue of whether server time is UTC or not is still muddy to me. I happen to have no idea whether my server's time is set in UTC or not. When I say 'date' I get my local time. When I say 'date -u', I get UTC time. So far so good, but what it's running internally, I don't know.

How do I find out? How do I set it to UTC if it's not? And do we really want to *require* that *every* server ever running OpenACS must have its internal clock set to UTC?

So if the server's time isn't UTC, should we still store datetimes in UTC? I suppose you would all argue yes here, and I don't have a problem with that.

The other two issues are:

1) I'd like to not require that everybody installs ref-timezones in order to run OpenACS, since it's so big. It should be possible to run a single-timezone site without it.

So either everything should be written so it works without ref-timezones (it seems to be already), or we need to split ref-timezones into a small and a large package somehow. Recommendations here would be welcome.

2) This will require that we run through each and every piece of code in the system that either inputs or outputs a date/time and change them. That's a lot of work. Do you have any good ideas for how to go about this, or is it just grunt, grunt, grunt?

/Lars

Collapse
9: Re: Timezones (response to 5)
Posted by Bob Cassels on
[I haven't done anything with ACS for years, so this may be out-of-date.]

Yes you want to store all times in UTC.  Really the only thing you care about is that the time zone is one that doesn't use daylight time.  But GMT is the only one guaranteed to never switch to daylight time, since that's a political decision and GMT is not political.  (If you have times in a zone that uses daylight time, time differences are not reliable.)

Most of the times running around ACS stuff comes from the database (e.g. Oracle SYSDATE).  To have SYSDATE in UTC, just do "export TZ=GMT" in the database startup script.  Depending on your Unix, you may be able to use "export TZ=UTC", but they do the same thing.  (I know there's a difference, but the time routines don't.)  GMT is more widely known.

Unix keeps time in UTC, but often gives you "local" time, controlled by TZ.

Of course you can use this trick in the startup code for the server, or whatever process is running the code that is asking for the time.  Then you don't have to worry about changing any code that asks for local time.

You will have to make sure that places that present times switch to the client's preferred zone.

Collapse
10: Re: Timezones (response to 9)
Posted by Jeff Davis on
One other small gotcha is that if you use MTS with oracle
you need to make sure the listener is started with TZ=GMT
as well.
Collapse
6: Re: Timezones (response to 1)
Posted by Jon Griffin on
Lars,

I will work on splitting ref-timezones. Any ideas on logical splits?

I can think of splits by region, past vs present and etc. What do you think?

Collapse
7: Re: Timezones (response to 1)
Posted by Lars Pind on
1) Split table definitions from data. That way we can reference the tables, and still run a single-timezone site without timezone info.

2) Split highly populated timezones from lighly populated ones. This would favor some people over others, though, and I don't particularly like that.

I think I'd prefer 1.

Collapse
8: Re: Timezones (response to 1)
Posted by Eduardo Pérez on
Timezones are just a human invention. All Unix servers must know UTC via time() or gettimeofday() system calls. Timezones are only used to display dates in the format the user wants.

So, date/times are always saved in UTC in the DB. And formated to the user with a format and timezone the user wants.

Server timezone doesn't have any meaning. A user can access a server anywhere in the world and the user wants to compare dates in the local timezone or in UTC.

The openacs.org server has a problem here, by default it outputs dates in an unknown timezone and it should use UTC since is not specified.

Server timezone is a default setting for the users of a system when only a local group of users will use that server.

So, the system interfaces should always return UTC date/times and you only use a timeformat and timezone when printing a date/time to html according to current user config.