time zone class method? (DT::F::MySQL)

2003-11-05 Thread Matt Sisk
Was there a compelling reason not to have a class method analagous to 
DefaultLocale() for timezones, such as DefaultTimezone()?

And if it were present, am I alone in finding it useful for the Format 
modules, such as DT::F::MySQL, where the zoneless strings are forced 
into the 'floating' timezone?

Although it is not strictly true that MySQL is timezone agnostic. You 
could construct a local datetime using the result of MySQL's 
UNIX_TIMESTAMP() function with DateTime's from_epoch() and set the tz to 
'local' -- the unix timestamp returned from MySQL appears to observe the 
timezone of the local machine.

As it now stands, DT::F::MySQL does not behave symmetrically for local 
DateTimes:

 use DateTime;
 use DateTime::Format::MySQL;
 $F = 'DateTime::Format::MySQL';

 $now = DateTime-now(time_zone = 'local');
 print now:  , $now-datetime, \n;
 print tz:   , $now-time_zone_long_name, \n;
 $mdt = $F-format_datetime($now);
 print mdt:  $mdt\n;
 $now = $F-parse_datetime($mdt);
 print now2: , $now-datetime, \n;
 print tz2:  , $now-time_zone_long_name, \n;
 $now-set_time_zone('local');
 print now2: , $now-datetime, \n;
 print tz2:  , $now-time_zone_long_name, \n;
In order to get symmetry, you have to first set_time_zone('UTC') to 
convert from 'floating', then set_time_zone('local') to get back to the 
original time.

Am I going about this the wrong way?

Thanks,
Matt



Re: time zone class method? (DT::F::MySQL)

2003-11-05 Thread Dave Rolsky
On Wed, 5 Nov 2003, Matt Sisk wrote:

 Was there a compelling reason not to have a class method analagous to
 DefaultLocale() for timezones, such as DefaultTimezone()?

Nope, no particular reason.  But thinking about it, it seems like a bad
idea.  Locale is something that I would think the end user always wants to
set for themselves.  OTOH, the standard of absent a time zone, we use
floating makes it easy for people to write modules that use DateTime
stuff internally without having to worry about the user have set the
default time zone for their own code.

It strikes me as potentially dangerous action at a distance, because
setting the time zone can impact a _lot_ of calculations, whereas setting
the locale impacts nothing except presentation, which shouldn't be the
concern of CPAN modules using DateTime internally.

 DateTimes:

   use DateTime;
   use DateTime::Format::MySQL;

   $F = 'DateTime::Format::MySQL';

   $now = DateTime-now(time_zone = 'local');
   print now:  , $now-datetime, \n;
   print tz:   , $now-time_zone_long_name, \n;
   $mdt = $F-format_datetime($now);
   print mdt:  $mdt\n;
   $now = $F-parse_datetime($mdt);
   print now2: , $now-datetime, \n;
   print tz2:  , $now-time_zone_long_name, \n;
   $now-set_time_zone('local');
   print now2: , $now-datetime, \n;
   print tz2:  , $now-time_zone_long_name, \n;

 In order to get symmetry, you have to first set_time_zone('UTC') to
 convert from 'floating', then set_time_zone('local') to get back to the
 original time.

 Am I going about this the wrong way?

No, this probably just needs some documentation in DT::F::MySQL about how
to handle the results of parsing.


-dave

/*===
House Absolute Consulting
www.houseabsolute.com
===*/


Re: time zone class method? (DT::F::MySQL)

2003-11-05 Thread Dave Rolsky
On Wed, 5 Nov 2003, Matt Sisk wrote:

 And as a convenience, I was suggesting this as equivalent:

 $dt3 = $dt1-clone(%overrides);

If the set() method accepted a time_zone parameter (which is trivial to
add), wouldn't this be equivalent to:

 $dt3 = $dt1-clone-set(%overrides);

??


-dave

/*===
House Absolute Consulting
www.houseabsolute.com
===*/


Re: time zone class method? (DT::F::MySQL)

2003-11-05 Thread Rick Measham
At 21:57 -0600 2003-11-05, Matt Sisk wrote:
Rick Measham wrote:

The problem above is that $dt-parameters() may return a key 
included in %overrides. So how about $dt-parameters( %overrides )?


As I corrected myself earlier, I should have made the $dt in 
$dt-parameters() more generic, rather than the self-same object. I 
was *deliberately* illustrating that you could override those 
parameters by flattening the hashes.

So (a simple example...pretend I have several parameters to overide):

%parms = $dt1-parameters;
%overrides = (locale = 'latvia');
$dt3-set(%parms, %overrides);
And as a convenience, I was suggesting this as equivalent:

$dt3 = $dt1-clone(%overrides);
But the same problem exists ... %parms will contain locale = 
'en_AU', so your call to set is now:

$dt3-set( locale='en_AU', year=2003 .. second = 27, time_zone = '-1100',
   locale='latvia'
);
So which locale gets used?

Cheers!
Rick


Re: time zone class method? (DT::F::MySQL)

2003-11-05 Thread Dave Rolsky
On Thu, 6 Nov 2003, Rick Measham wrote:

 But the same problem exists ... %parms will contain locale =
 'en_AU', so your call to set is now:

 $dt3-set( locale='en_AU', year=2003 .. second = 27, time_zone = '-1100',
 locale='latvia'
 );

 So which locale gets used?

The second.  It's entirely, deterministic, because it's being assigned in
order to a hash, so last instance of a key always wins.  In fact, that's
perfectly valid Perl style, something like:

 my %params_to_use = ( %defaults, %user_overrides );


-dave

/*===
House Absolute Consulting
www.houseabsolute.com
===*/