On Fri, 31 Jan 2003, John Peacock wrote: > Let me think out loud now. If we are always storing time _and_ TZ, then it > certainly make more sense to me to use UTC to store the time. How's this for a > good example (pseudo-code): > > my $t1 = new DateTime::Simple ("2002-12-30T08:00:00", TZ => "EST"); > my $t2 = new DateTime::Simple ("2002-12-30T08:00:00", TZ => "MST"); > > my $diff = $t2-$t1; > > If we store the internal value as UTC, then differences are a simple matter of > taking the difference between the internal UTC values. If we don't store > internally as UTC, then we would need to adjust each $t to a common TZ prior to > mathematic operations.
Before we get too far down the paths of already solved problems, let me describe how the internals work. When a user creates a DateTime, we assume that they are telling us the _local_ time, so that '2002-12-30T08:00:00' in EST is really '2002-12-30T03:00:00' in UTC. When a user asks for some datetime component, like hour, day of week, and so on, this is calculcated from the local time. So the above would report an hour of "8:00". But when doing any sort of date math (including comparisons) we have to use UTC time. To make this all work and be fairly efficient, we actually store both UTC and local times (and broken down components for local times) internally. We could store just one of these things and calculate the rest of demand, but there's really not much to gain from that. None of this has anything to do with my question, however, which is this: If I do this: # UTC time my $dt = DateTime->new( year => 2000, month => 5, day => 6, hour => 7, minute => 15, time_zone => 0 ); print $dt->hour; # prints 7 $dt->set( time_zone => 'America/Chicago' ); print $dt->hour; # prints 1 or 7? In other words, does setting the time zone cause us to recalculate local time based on the current UTC (prints 1), or does it cause us to recalculate UTC based on the local time (prints 7). I lean towards the former, but we might need both. -dave /*======================= House Absolute Consulting www.houseabsolute.com =======================*/