perl.datetime http://www.nntp.perl.org/group/perl.datetime/ ... Copyright 1998-2013 perl.org Wed, 22 May 2013 06:24:25 +0000 ask@perl.org Re: DateTime setting invalid zone. by Bill Moseley On Wed, Mar 13, 2013 at 9:10 AM, Dave Rolsky &lt;autarch@urth.org&gt; wrote:<br/><br/>&gt; On Tue, 12 Mar 2013, Bill Moseley wrote:<br/>&gt;<br/>&gt; So, I found some old that wrapped a set_time_zone in an eval.<br/>&gt;&gt;<br/>&gt;&gt; my $dt = DateTime-&gt;new(<br/>&gt;&gt; year =&gt; 2013,<br/>&gt;&gt; month =&gt; 3,<br/>&gt;&gt; day =&gt; 10,<br/>&gt;&gt; hour =&gt; 2,<br/>&gt;&gt; minute =&gt; 4,<br/>&gt;&gt; time_zone =&gt; &#39;floating&#39;,<br/>&gt;&gt; );<br/>&gt;&gt;<br/>&gt;&gt; eval { $dt-&gt;set_time_zone( &#39;America/Los_Angeles&#39; ); };<br/>&gt;&gt;<br/>&gt;&gt; print &quot;$dt &quot; . $dt-&gt;time_zone . &quot;\n&quot;;<br/>&gt;&gt;<br/>&gt;&gt;<br/>&gt;&gt; The code was using the eval to check if the timezone set failed, and if it<br/>&gt;&gt; did went on to do something else with $dt (like set to UTC). But, it<br/>&gt;&gt; seems like even if it fails the time zone gets set. The above returns<br/>&gt;&gt; this<br/>&gt;&gt; invalid time:<br/>&gt;&gt;<br/>&gt;&gt; 2013-03-10T02:04:00<br/>&gt;&gt; DateTime::TimeZone::America::**Los_Angeles=HASH(**0x7fc4c2aafc90)<br/>&gt;&gt;<br/>&gt;&gt; My question is should DateTime associate that timezone to $dt if the<br/>&gt;&gt; set_time_zone call actually throws an exception?<br/>&gt;&gt;<br/>&gt;<br/>&gt; This is almost certainly a bug.<br/>&gt;<br/><br/>Ok, filed as:<br/><br/>https://rt.cpan.org/Ticket/Display.html?id=83940<br/><br/><br/>Thanks,<br/><br/>-- <br/>Bill Moseley<br/>moseley@hank.org<br/><br/> http://www.nntp.perl.org/group/perl.datetime/2013/03/msg7932.html Thu, 14 Mar 2013 11:39:42 +0000 Re: DateTime setting invalid zone. by Mark Stosberg On 03/13/2013 12:10 PM, Dave Rolsky wrote:<br/>&gt; On Tue, 12 Mar 2013, Bill Moseley wrote:<br/>&gt; <br/>&gt;&gt; So, I found some old that wrapped a set_time_zone in an eval.<br/>&gt;&gt;<br/>&gt;&gt; my $dt = DateTime-&gt;new(<br/>&gt;&gt; year =&gt; 2013,<br/>&gt;&gt; month =&gt; 3,<br/>&gt;&gt; day =&gt; 10,<br/>&gt;&gt; hour =&gt; 2,<br/>&gt;&gt; minute =&gt; 4,<br/>&gt;&gt; time_zone =&gt; &#39;floating&#39;,<br/>&gt;&gt; );<br/>&gt;&gt;<br/>&gt;&gt; eval { $dt-&gt;set_time_zone( &#39;America/Los_Angeles&#39; ); };<br/>&gt;&gt;<br/>&gt;&gt; print &quot;$dt &quot; . $dt-&gt;time_zone . &quot;\n&quot;;<br/>&gt;&gt;<br/>&gt;&gt;<br/>&gt;&gt; The code was using the eval to check if the timezone set failed, and<br/>&gt;&gt; if it<br/>&gt;&gt; did went on to do something else with $dt (like set to UTC). But, it<br/>&gt;&gt; seems like even if it fails the time zone gets set. The above returns<br/>&gt;&gt; this<br/>&gt;&gt; invalid time:<br/>&gt;&gt;<br/>&gt;&gt; 2013-03-10T02:04:00<br/>&gt;&gt; DateTime::TimeZone::America::Los_Angeles=HASH(0x7fc4c2aafc90)<br/>&gt;&gt;<br/>&gt;&gt; My question is should DateTime associate that timezone to $dt if the<br/>&gt;&gt; set_time_zone call actually throws an exception?<br/>&gt; <br/>&gt; This is almost certainly a bug.<br/><br/>Would a fix to first clone the object, attempt to change time zone, and<br/>then only set the timezone on the original object if it succeeds?<br/><br/> Mark<br/><br/> http://www.nntp.perl.org/group/perl.datetime/2013/03/msg7931.html Wed, 13 Mar 2013 17:34:44 +0000 Re: DateTime setting invalid zone. by Dave Rolsky On Tue, 12 Mar 2013, Bill Moseley wrote:<br/><br/>&gt; So, I found some old that wrapped a set_time_zone in an eval.<br/>&gt;<br/>&gt; my $dt = DateTime-&gt;new(<br/>&gt; year =&gt; 2013,<br/>&gt; month =&gt; 3,<br/>&gt; day =&gt; 10,<br/>&gt; hour =&gt; 2,<br/>&gt; minute =&gt; 4,<br/>&gt; time_zone =&gt; &#39;floating&#39;,<br/>&gt; );<br/>&gt;<br/>&gt; eval { $dt-&gt;set_time_zone( &#39;America/Los_Angeles&#39; ); };<br/>&gt;<br/>&gt; print &quot;$dt &quot; . $dt-&gt;time_zone . &quot;\n&quot;;<br/>&gt;<br/>&gt;<br/>&gt; The code was using the eval to check if the timezone set failed, and if it<br/>&gt; did went on to do something else with $dt (like set to UTC). But, it<br/>&gt; seems like even if it fails the time zone gets set. The above returns this<br/>&gt; invalid time:<br/>&gt;<br/>&gt; 2013-03-10T02:04:00<br/>&gt; DateTime::TimeZone::America::Los_Angeles=HASH(0x7fc4c2aafc90)<br/>&gt;<br/>&gt; My question is should DateTime associate that timezone to $dt if the<br/>&gt; set_time_zone call actually throws an exception?<br/><br/>This is almost certainly a bug.<br/><br/><br/>-dave<br/><br/>/*============================================================<br/>http://VegGuide.org http://blog.urth.org<br/>Your guide to all that&#39;s veg House Absolute(ly Pointless)<br/>============================================================*/<br/> http://www.nntp.perl.org/group/perl.datetime/2013/03/msg7930.html Wed, 13 Mar 2013 16:10:39 +0000 DateTime setting invalid zone. by Bill Moseley So, I found some old that wrapped a set_time_zone in an eval.<br/><br/>my $dt = DateTime-&gt;new(<br/> year =&gt; 2013,<br/> month =&gt; 3,<br/> day =&gt; 10,<br/> hour =&gt; 2,<br/> minute =&gt; 4,<br/> time_zone =&gt; &#39;floating&#39;,<br/>);<br/><br/>eval { $dt-&gt;set_time_zone( &#39;America/Los_Angeles&#39; ); };<br/><br/>print &quot;$dt &quot; . $dt-&gt;time_zone . &quot;\n&quot;;<br/><br/><br/>The code was using the eval to check if the timezone set failed, and if it<br/>did went on to do something else with $dt (like set to UTC). But, it<br/>seems like even if it fails the time zone gets set. The above returns this<br/>invalid time:<br/><br/>2013-03-10T02:04:00<br/>DateTime::TimeZone::America::Los_Angeles=HASH(0x7fc4c2aafc90)<br/><br/>My question is should DateTime associate that timezone to $dt if the<br/>set_time_zone call actually throws an exception?<br/><br/><br/>-- <br/>Bill Moseley<br/>moseley@hank.org<br/><br/> http://www.nntp.perl.org/group/perl.datetime/2013/03/msg7929.html Wed, 13 Mar 2013 02:35:03 +0000 Re: How to correctly add a duration to not have it result in invalid date? by Andrew Davis Actually, most software that needs to do time arithmetic accurately does not use UTC internally. <br/>Leap seconds make calculations for future times problematic using UTC. See<br/>http://en.wikipedia.org/wiki/Leap_second<br/><br/>Software in my field (space physics) uses epochs (seconds elapsed since an instant), or TAI.<br/>Conversion to &quot;human friendly&quot; dates/times such as UTC is done as the last step, and <br/>requires a leap second lookup table.<br/><br/>Andrew J Davis<br/>(626) 429 0844 (cell)<br/><br/>On Mar 8, 2013, at 11:48 PM, Jim Monty &lt;jim.monty@yahoo.com&gt; wrote:<br/><br/>&gt; Bill Moseley wrote:<br/>&gt;&gt; UTC is a timezone, too.<br/>&gt; <br/>&gt; UTC is only ever a &quot;time zone&quot; in implementations of computer models<br/>&gt; of time and timekeeping such as Perl DateTime. In fact, UTC is, by<br/>&gt; definition, NOT a time zone. It&#39;s the baseline reference time from<br/>&gt; which time in zones are reckoned. A time expressed in UTC records a<br/>&gt; moment in time (an &quot;instant&quot; in ISO 8601 parlance) without regard to<br/>&gt; geography or geopolitical boundaries. It&#39;s the time everywhere and<br/>&gt; nowhere. Zulu time.<br/>&gt; <br/>&gt; A time expressed in UTC is absolute and universal.<br/>&gt; <br/>&gt; I think this is the point Karen was emphasizing: don&#39;t record times<br/>&gt; in a computer database in local time (in time zones) because these<br/>&gt; expressions of time are rule-based and have too many anomalies in them,<br/>&gt; which UTC representations of time do not have: a missing hour in some<br/>&gt; days, a repeated hour in other days, etc.<br/>&gt; <br/>&gt;&gt; In our database we use &quot;timestamp with time zone&quot; and it doesn&#39;t matter<br/>&gt;&gt; what timezone the database session uses as long as we use the timezone<br/>&gt;&gt; when parsing the column data.<br/>&gt; <br/>&gt; For me, it helps to think of the time zone as an attribute of a person<br/>&gt; who needs to know what time it is, either now or when some even occurs.<br/>&gt; The time zone is not an attribute of a moment in time. Time zones are<br/>&gt; more about location than they are about time.<br/>&gt; <br/>&gt; So imagine if you abandoned all efforts to record instants in local time<br/>&gt; and instead always recorded them in the single, universal reference<br/>&gt; time, UTC. Perform all date and time arithmetic using these moments<br/>&gt; uniformly recorded in UTC. Instead of storing the time zones along with<br/>&gt; each moment in time, store the time zones of the people who need to<br/>&gt; have the times expressed to them in their personal local time.<br/>&gt; <br/>&gt; This is what Microsoft Office Outlook does. I suspect it&#39;s how most<br/>&gt; modern computer software handles timestamps.<br/>&gt; <br/>&gt; Jim Monty<br/><br/> http://www.nntp.perl.org/group/perl.datetime/2013/03/msg7928.html Tue, 12 Mar 2013 08:57:44 +0000 Re: How to correctly add a duration to not have it result in invalid date? by Bill Moseley On Sun, Mar 10, 2013 at 4:59 PM, Jim Monty &lt;jim.monty@yahoo.com&gt; wrote:<br/><br/>&gt;<br/>&gt; I believe this is how you might represent the RELATIVE time noon in<br/>&gt; Caracas on October 12, 2018 using the iCalendar standard:<br/>&gt;<br/>&gt; DTSTART;TZID=America/Caracas:20181012T120000<br/>&gt;<br/><br/>So, to compare that to some point in time (e.g. now() ) it must be turned<br/>into, well, a point in time like UTC based on what it knows about timezones<br/>-- at the moment. It&#39;s imposible to know what point in time that is until<br/>it actually happens, right? It&#39;s politics.<br/><br/>Hard to imagine storing that form in a database and doing queries where<br/>offset calculations must be done at the time a query is run. Seems very<br/>expensive.<br/><br/><br/>&gt;<br/>&gt; The iCalendar standard specifies how to handle daylight/standard time<br/>&gt; boundary cases such as when the same time occurs twice on the same day,<br/>&gt; or when a time doesn&#39;t occur on a transitional day&mdash;like today in most<br/>&gt; of the United States!<br/>&gt;<br/><br/>You know, yesterday I got curious and set both my Android phone and my<br/>wife&#39;s iPhone for a 2:30am alarm. I was curious when it would go off.<br/>Unfortunately, I told my wife about this and the experiment was quickly<br/>called off.<br/><br/><br/><br/>-- <br/>Bill Moseley<br/>moseley@hank.org<br/><br/> http://www.nntp.perl.org/group/perl.datetime/2013/03/msg7927.html Mon, 11 Mar 2013 05:01:29 +0000 Re: How to correctly add a duration to not have it result in invalid date? by Jim Monty Bill Moseley wrote:<br/>&gt; I don&#39;t want to drag discussion on too much longer, and moving way off<br/>&gt; the original topic...<br/><br/>I don&#39;t see this discussion drifting off topic. I see it now getting to<br/>the very heart of the matter.<br/><br/>&gt; In a web app a user might enter a time, say 9:00am in the future, when<br/>&gt; some event should happen. We know their timezone is America/New_York.<br/>&gt;<br/>&gt; So, we create a DateTime object DateTime-&gt;new ( hour =&gt; 9, time_zone =&gt;<br/>&gt; &#39;America/New_York&#39;, ... );<br/>&gt;<br/>&gt; Then we use DateTime::Format::Pg to format that to store in a &quot;timestamp<br/>&gt; with time zone&quot; column.<br/>&gt;<br/>&gt; Am I correct that DateTime (or the formatter) does its best to determine<br/>&gt; the *offset* from UTC at that time in the future and stores that?<br/>&gt;<br/>&gt; Would you implement that differently?<br/><br/>Offsets from UTC don&#39;t record any useful information about time zones.<br/>For the kind of scheduling application you&#39;re describing, an offset from<br/>UTC isn&#39;t helpful because it doesn&#39;t record the important information<br/>you need to know about the future point in time at which something must<br/>occur; namely, where&mdash;in what geopolitical locale, or time zone&mdash;the user<br/>is asserting that some event must occur in the future.<br/><br/>This is one of the reasons that, for the purpose of storing moments in<br/>time in a computer database, it&#39;s better to normalize their<br/>representation to a single reference time scale such as UTC. At the very<br/>least, doing this saves a lot of needless arithmetic with purposeless<br/>offsets.<br/><br/>&gt; But, between now and that future time politics could change DST resulting<br/>&gt; in the event not really happening at 9am in New York on that day, correct?<br/>&gt; That&#39;s a risk.<br/>&gt;<br/>&gt; There&#39;s too many ambiguities. Does the user really mean 9am in New York?<br/>&gt; Or 9am in whatever their current time zone is on that day? Maybe in this<br/>&gt; case should really store with a local time zone &quot;9am America/New_York&quot;.<br/>&gt;<br/>&gt; Probably best to not schedule anything too far into the future...<br/><br/>You can&#39;t reliably represent a future RELATIVE moment in time such as<br/>noon in Caracas, Venezula on October 12, 2018 using an ABSOLUTE instant<br/>you assert today. You can&#39;t be certain right now which instant noon will<br/>be on that future date in Caracas. So just guessing an ABSOLUTE instant<br/>now and storing that guess in a computer database won&#39;t suffice for the<br/>purpose of signaling some event to occur at that RELATIVE moment in the<br/>future and in that place&mdash;or in any other place at that same instant<br/>reckoned from noon in Caracas on October 12, 2018.<br/><br/>You can, however, reliably represent future RELATIVE instants in<br/>computer software. You just need a protocol to do this. Storing<br/>ABSOLUTE timestamps alone&mdash;using any time scale or in any time zone&mdash;<br/>won&#39;t cut it. You can invent your own protocol, or you can use an<br/>existing one such as iCalendar. I believe iCalendar (RFC 5545) is<br/>designed to enable exactly the kind of RELATIVE time representation<br/>for scheduling events that you describe.<br/><br/>The Perl DateTime documentation states: &quot;The default time zone for new<br/>DateTime objects, except where stated otherwise, is the &#39;floating&#39; time<br/>zone. This concept comes from the iCal [iCalendar] standard.&quot;<br/><br/>The iCalendar standard defines three kinds (&quot;forms&quot;) of times:<br/><br/>&nbsp;&nbsp;&nbsp; FORM #1: DATE WITH LOCAL TIME (&quot;floating&quot;)<br/>&nbsp;&nbsp;&nbsp; FORM #2: DATE WITH UTC TIME<br/>&nbsp;&nbsp;&nbsp; FORM #3: LOCAL TIME AND TIME ZONE REFERENCE<br/><br/>&nbsp;&nbsp;&nbsp; (See http://tools.ietf.org/html/rfc5545#page-31.)<br/><br/>I believe this is how you might represent the RELATIVE time noon in<br/>Caracas on October 12, 2018 using the iCalendar standard:<br/><br/>&nbsp;&nbsp;&nbsp; DTSTART;TZID=America/Caracas:20181012T120000<br/><br/>The iCalendar standard specifies how to handle daylight/standard time<br/>boundary cases such as when the same time occurs twice on the same day,<br/>or when a time doesn&#39;t occur on a transitional day&mdash;like today in most<br/>of the United States!<br/><br/>Needless to say, there are plenty of Perl CPAN modules for handling<br/>iCalendar data, including DateTime::Event::ICal.<br/><br/>(Disclaimer: I don&#39;t know the iCalendar standard well and I&#39;ve never<br/>done the kind of scheduling software programming we&#39;re discussing here.<br/>What I&#39;ve written in this email is based on the little research I did to<br/>try to answer your questions as best I could. If, knowing this, you say<br/>I should have kept my pie hole shut from the beginning, I won&#39;t argue<br/>with you. Hopefully, however, I&#39;ve contributed at least one useful idea.)<br/><br/>-- <br/>Jim Monty<br/>Tempe, Arizona USA<br/> http://www.nntp.perl.org/group/perl.datetime/2013/03/msg7926.html Sun, 10 Mar 2013 23:59:48 +0000 Re: How to correctly add a duration to not have it result in invalid date? by Bill Moseley I don&#39;t want to drag discussion on too much longer, and moving way off the<br/>original topic, but I do have an implementation question.<br/><br/>On Fri, Mar 8, 2013 at 11:48 PM, Jim Monty &lt;jim.monty@yahoo.com&gt; wrote:<br/><br/>&gt; Bill Moseley wrote:<br/>&gt; &gt; UTC is a timezone, too.<br/>&gt;<br/><br/>Yes, poor choice of words. That sentence I wrote doesn&#39;t make much sense.<br/> I think I was saying to represent a *point in time* you need a timezone,<br/>where a timezone is an offset from UTC (including +00:00 offset). I was<br/>thinking about Postgresql at that time. But, that&#39;s still wrong for the<br/>word timezone.<br/><br/>I&#39;m not sure how Postgresql internally represents its &quot;timestamp with time<br/>zone&quot;, but it looks more like it&#39;s a &quot;timestamp with offset&quot;.<br/><br/>2012-09-07 15:26:40.338969-07<br/><br/><br/>Offset is from UTC, of course, so that&#39;s always a point in time, correct?<br/><br/><br/>I think this is the point Karen was emphasizing: don&#39;t record times<br/>&gt; in a computer database in local time (in time zones) because these<br/>&gt; expressions of time are rule-based and have too many anomalies in them,<br/>&gt; which UTC representations of time do not have: a missing hour in some<br/>&gt; days, a repeated hour in other days, etc.<br/>&gt;<br/><br/>Again, I agree with Karen.<br/><br/>There&#39;s no perfect answer, right? We (humans) mostly work with local<br/>times. Say, I set my alarm for 9am local time on March 8th 2015 (when DST<br/>is scheduled to begin) and then convert that to UTC and store. Then if DST<br/>is abolished between now and then my alarm will go off at the &quot;wrong&quot; local<br/>time.<br/><br/><br/>So, here&#39;s the implementation question.<br/><br/>In a web app a user might enter a time, say 9:00am in the future, when some<br/>event should happen. We know their timezone is America/New_York.<br/><br/>So, we create a DateTime object DateTime-&gt;new ( hour =&gt; 9, time_zone =&gt;<br/>&#39;America/New_York&#39;, ... );<br/><br/>Then we use DateTime::Format::Pg to format that to store in a &quot;timestamp<br/>with time zone&quot; column.<br/><br/>Am I correct that DateTime (or the formatter) does its best to determine the<br/>* offset* from UTC at that time in the future and stores that?<br/><br/>Would you implement that differently?<br/><br/>But, between now and that future time politics could change DST resulting<br/>in the event not really happening at 9am in New York on that day, correct?<br/> That&#39;s a risk.<br/><br/>There&#39;s too many ambiguities. Does the user really mean 9am in New York?<br/> Or 9am in whatever their current time zone is on that day? Maybe in this<br/>case should really store with a local time zone &quot;9am America/New_York&quot;.<br/><br/>Probably best to not schedule anything too far into the future...<br/><br/><br/>-- <br/>Bill Moseley<br/>moseley@hank.org<br/><br/> http://www.nntp.perl.org/group/perl.datetime/2013/03/msg7925.html Sat, 09 Mar 2013 16:25:36 +0000 Re: How to correctly add a duration to not have it result in invalid date? by Jim Monty Bill Moseley wrote:<br/>&gt; UTC is a timezone, too.<br/><br/>UTC is only ever a &quot;time zone&quot; in implementations of computer models<br/>of time and timekeeping such as Perl DateTime. In fact, UTC is, by<br/>definition, NOT a time zone. It&#39;s the baseline reference time from<br/>which time in zones are reckoned. A time expressed in UTC records a<br/>moment in time (an &quot;instant&quot; in ISO 8601 parlance) without regard to<br/>geography or geopolitical boundaries. It&#39;s the time everywhere and<br/>nowhere. Zulu time.<br/><br/>A time expressed in UTC is absolute and universal.<br/><br/>I think this is the point Karen was emphasizing:&nbsp; don&#39;t record times<br/>in a computer database in local time (in time zones) because these<br/>expressions of time are rule-based and have too many anomalies in them,<br/>which UTC representations of time do not have:&nbsp; a missing hour in some<br/>days, a repeated hour in other days, etc.<br/><br/>&gt; In our database we use &quot;timestamp with time zone&quot; and it doesn&#39;t matter<br/>&gt; what timezone the database session uses as long as we use the timezone<br/>&gt; when parsing the column data.<br/><br/>For me, it helps to think of the time zone as an attribute of a person<br/>who needs to know what time it is, either now or when some even occurs.<br/>The time zone is not an attribute of a moment in time. Time zones are<br/>more about location than they are about time.<br/><br/>So imagine if you abandoned all efforts to record instants in local time<br/>and instead always recorded them in the single, universal reference<br/>time, UTC. Perform all date and time arithmetic using these moments<br/>uniformly recorded in UTC. Instead of storing the time zones along with<br/>each moment in time, store the time zones of the people who need to<br/>have the times expressed to them in their personal local time.<br/><br/>This is what Microsoft Office Outlook does. I suspect it&#39;s how most<br/>modern computer software handles timestamps.<br/><br/>Jim Monty<br/> http://www.nntp.perl.org/group/perl.datetime/2013/03/msg7924.html Sat, 09 Mar 2013 07:48:12 +0000 Re: How to correctly add a duration to not have it result in invalid date? by Bill Moseley On Fri, Mar 8, 2013 at 3:04 PM, Karen Etheridge &lt;perl@froods.org&gt; wrote:<br/><br/>&gt;<br/>&gt; my $0.02: **always** store timestamps in ISO8601 format (UTC), or in unix<br/>&gt; epoch (integer) format **only**. Local timezones should only get applied<br/>&gt; when rendering data for user consumption - i.e. as late as possible, and<br/>&gt; after all calculations have been performed. When processing timestamps<br/>&gt; input by a user, convert to UTC as soon as possible, before storage and<br/>&gt; before applying any math.<br/>&gt;<br/><br/>I know what you are saying and it&#39;s good advice. UTC is a timezone, too.<br/>If you want to represent a point in time so that you can later render it in<br/>a user&#39;s timezone or compare it to another time you must include the time<br/>zone.<br/><br/>In our database we use &quot;timestamp with time zone&quot; and it doesn&#39;t matter<br/>what timezone the database session uses as long as we use the timezone when<br/>parsing the column data.<br/><br/>If you have two DateTime objects (where is_floating is false) then AFAIK<br/>they can be compared regardless of time zone of each DateTime, object.<br/> That is, they both represent a point in time.<br/><br/><br/>When rendering we convert to the user&#39;s timezone (as they have chosen in<br/>their preferences).<br/><br/>And as Zefram noted, &quot;durations are not arithmetically well behaved&quot;, and<br/>so it using UTC is useful when working with durations for the DST issues I<br/>originally posted about.<br/><br/><br/>&gt; There&#39;s a good (and lengthy) discussion at<br/>&gt; https://metacpan.org/module/DateTime#How-DateTime-Math-Works, which ends<br/>&gt; with very similar advice.<br/>&gt;<br/><br/>Good read, yes.<br/><br/><br/><br/>-- <br/>Bill Moseley<br/>moseley@hank.org<br/><br/> http://www.nntp.perl.org/group/perl.datetime/2013/03/msg7923.html Sat, 09 Mar 2013 01:24:36 +0000 Re: How to correctly add a duration to not have it result in invalid date? by Karen Etheridge On Fri, Mar 08, 2013 at 07:06:32AM -0800, Bill Moseley wrote:<br/>&gt; With fifteen or so developers with all different levels of Perl skills not<br/>&gt; all are going to understand or know the specifics of when duration math<br/>&gt; might fail. And the hard part is it might not fail for months or years<br/>&gt; after the code is written.<br/>&gt; ... But, I&#39;m<br/>&gt; wondering if there&#39;s an idiom or rule I could provide them so that the math<br/>&gt; will at least not fail.<br/>&gt; Like, &quot;always defined durations in terms of hours&quot; (or seconds?) or &quot;always<br/>&gt; convert to UTC before adding a duration&quot;.<br/><br/>my $0.02: **always** store timestamps in ISO8601 format (UTC), or in unix<br/>epoch (integer) format **only**. Local timezones should only get applied<br/>when rendering data for user consumption - i.e. as late as possible, and<br/>after all calculations have been performed. When processing timestamps<br/>input by a user, convert to UTC as soon as possible, before storage and<br/>before applying any math.<br/><br/>There&#39;s a good (and lengthy) discussion at<br/>https://metacpan.org/module/DateTime#How-DateTime-Math-Works, which ends<br/>with very similar advice.<br/><br/> http://www.nntp.perl.org/group/perl.datetime/2013/03/msg7922.html Fri, 08 Mar 2013 23:04:24 +0000 Re: How to correctly add a duration to not have it result ininvalid date? by Zefram Bill Moseley wrote:<br/>&gt;Again, developers of varying skills come and go and work on existing code.<br/>&gt; So, they may not have any idea that &quot;$start_time&quot; has a timezone or think<br/>&gt;about DST issues. Or that a day isn&#39;t always 24 hours.<br/><br/>So teach them. If they&#39;re going to be working a lot in this problem<br/>domain, they ought to learn enough about it to avoid making basic errors.<br/><br/>&gt;What if DatTime Duration objects had a flag to say do the math in UTC?<br/>&gt; Would that avoid the problem if it possibly failing?<br/><br/>That would make the issue of what a DateTime::Duration actually represents<br/>even more confusing than it already is.<br/><br/>&gt;In my experience the floating times open up other headaches. We store all<br/>&gt;times with a timezone -- we would rarely have something like &quot;9am your<br/>&gt;time&quot; because of the ambiguity.<br/><br/>I&#39;m not suggesting that *you* forget which timezone applies. I&#39;m<br/>suggesting that you do the date arithmetic without telling *DateTime*<br/>to apply a timezone. Do the date arithmetic in &quot;floating&quot; timezone, and<br/>store the resulting local time along with the timezone name. To compare<br/>the current time against this stored threshold, take the current time,<br/>express it in the stored timezone, then take the resulting current local<br/>time and compare that (sans timezone) against the stored local time.<br/><br/>-zefram<br/> http://www.nntp.perl.org/group/perl.datetime/2013/03/msg7921.html Fri, 08 Mar 2013 15:21:18 +0000 Re: How to correctly add a duration to not have it result in invalid date? by Bill Moseley Thanks for the responses!<br/><br/>With fifteen or so developers with all different levels of Perl skills not<br/>all are going to understand or know the specifics of when duration math<br/>might fail. And the hard part is it might not fail for months or years<br/>after the code is written.<br/><br/>Obviously, they should understand that adding a duration of, say, days may<br/>not mean exactly multiples 24 hours, and it could fail. But, I&#39;m<br/>wondering if there&#39;s an idiom or rule I could provide them so that the math<br/>will at least not fail.<br/><br/>Like, &quot;always defined durations in terms of hours&quot; (or seconds?) or &quot;always<br/>convert to UTC before adding a duration&quot;.<br/><br/>True, there&#39;s no easy solution.<br/><br/><br/>&gt;<br/>&gt; &gt;What would happen if duration calculations were always done in UTC?<br/>&gt;<br/>&gt; That would avoid DST-based failures. It does so by applying a different<br/>&gt; meaning of &quot;day&quot; from that which you&#39;re currently using.<br/>&gt;<br/><br/><br/>Again, developers of varying skills come and go and work on existing code.<br/> So, they may not have any idea that &quot;$start_time&quot; has a timezone or think<br/>about DST issues. Or that a day isn&#39;t always 24 hours.<br/><br/>$access-&gt;disable if $start_time-&gt;add( days =&gt; $day_limit ) &lt; $now;<br/><br/>That might be important contractually that it happens at some point instead<br/>of never.<br/><br/>What if DatTime Duration objects had a flag to say do the math in UTC?<br/> Would that avoid the problem if it possibly failing?<br/><br/>$access-&gt;disable if $start_time-&gt;add( days =&gt; $day_limit, in_utc =&gt; 1 ) &lt;<br/>$now;<br/><br/><br/><br/>&gt; Maybe you actually want a definite UT time for the end of the period.<br/>&gt; If that&#39;s the case, you probably want to interpret the duration in UT.<br/>&gt; Or maybe you need the end of the period to be defined in local time.<br/>&gt; In that case you&#39;d be better just storing a notional local time without<br/>&gt; regard to current projection of whether DST will skip it. (You do that<br/>&gt; with DateTime by using the &quot;floating&quot; pseudo-timezone.)<br/>&gt;<br/><br/>In my experience the floating times open up other headaches. We store all<br/>times with a timezone -- we would rarely have something like &quot;9am your<br/>time&quot; because of the ambiguity.<br/><br/><br/>Thanks very much for the comments.<br/><br/><br/>-- <br/>Bill Moseley<br/>moseley@hank.org<br/><br/> http://www.nntp.perl.org/group/perl.datetime/2013/03/msg7920.html Fri, 08 Mar 2013 15:07:16 +0000 Re: How to correctly add a duration to not have it result ininvalid date? by Zefram Bill Moseley wrote:<br/>&gt;If $dt and $duration can be anything, what&#39;s the best way to prevent adding<br/>&gt;a $duration to a $dt and having it land on a non-existent date?<br/><br/>Depends how broad your &quot;anything&quot; class is for durations. Calendar<br/>durations are not arithmetically well behaved, and there are several<br/>distinct ways in which calendar datetimes can fail to exist.<br/><br/>&gt;What would happen if duration calculations were always done in UTC?<br/><br/>That would avoid DST-based failures. It does so by applying a different<br/>meaning of &quot;day&quot; from that which you&#39;re currently using.<br/><br/>You need to decide what you actually mean by &quot;day&quot; when describing<br/>these expiry periods. You also need to decide whether you actually<br/>need a definite DateTime to represent the end of the period. Consider,<br/>especially when the period is years long, that DST rules are liable to<br/>before the period ends. Currently you&#39;re performing the addition in<br/>local time and (by virtue of putting the result into a DateTime with<br/>specified time zone) converting the result to UT based on the current<br/>best guess of what offset the zone will have at that time.<br/><br/>Maybe you actually want a definite UT time for the end of the period.<br/>If that&#39;s the case, you probably want to interpret the duration in UT.<br/>Or maybe you need the end of the period to be defined in local time.<br/>In that case you&#39;d be better just storing a notional local time without<br/>regard to current projection of whether DST will skip it. (You do that<br/>with DateTime by using the &quot;floating&quot; pseudo-timezone.)<br/><br/>-zefram<br/> http://www.nntp.perl.org/group/perl.datetime/2013/03/msg7919.html Fri, 08 Mar 2013 09:22:51 +0000 Re: How to correctly add a duration to not have it result in invaliddate? by Thomas Klausner Hi!<br/><br/>On Thu, Mar 07, 2013 at 08:34:47PM -0800, Bill Moseley wrote:<br/> <br/>&gt; Invalid local time for date in time zone: America/Los_Angeles<br/><br/>I&#39;ve had the same problem several times in the past (mostly in <br/>America/Sao_Paulo, which has the very stupid idea of making the switch <br/>to winter time at 0:00 (so there is no 00:00:00 - 00:59:59 on that <br/>day)).<br/><br/>You can probably find the discussion in the archive. I suggested some <br/>fixes/workarounds, but they were rejected for being not correct. (They <br/>are not correct in a very technical sense, but would be extremly <br/>practical, IMO).<br/><br/>&gt; What would happen if duration calculations were always done in UTC?<br/><br/>This is the correct (albeit complex) solution. Always do date math in <br/>UTC, and convert back to local time zone later. I find this solution not <br/>very practical or perlish, but other solutions probably won&#39;t be <br/>accepted into DateTime (or weren&#39;t when I tried the last time...)<br/><br/>Greetings,<br/>domm<br/><br/><br/>-- <br/>#!/usr/bin/perl http://domm.plix.at<br/>for(ref bless{},just&#39;another&#39;perl&#39;hacker){s-:+-$&quot;-g&amp;&amp;print$_.$/}<br/> http://www.nntp.perl.org/group/perl.datetime/2013/03/msg7918.html Fri, 08 Mar 2013 09:17:50 +0000 How to correctly add a duration to not have it result in invalid date? by Bill Moseley Last night abou 2:15am we had some automated tests fail with this error:<br/><br/>Invalid local time for date in time zone: America/Los_Angeles<br/><br/><br/>The problem was that (for some reason) we had a duration object of ( years<br/>=&gt; 7, days =&gt; 1 ) which we added to DateTime-&gt;now which ended up March 8,<br/>2020 which is a DST change -- and 2:15am does not exist in that time zone<br/>on that date.<br/><br/>If $dt and $duration can be anything, what&#39;s the best way to prevent adding<br/>a $duration to a $dt and having it land on a non-existent date?<br/><br/>I realize that durations are a bit ambiguous, but is it reasonable to write<br/>something like<br/><br/> $expires_time = $start_time-&gt;clone-&gt;add( days =&gt; $expire_days ); # or<br/>even ( years =&gt; 7, days =&gt; 1 ) like above<br/><br/>and not have it throw an exception? I suspect most of us expect (and<br/>hope) that $expires_days in the future will exist. Or should we always<br/>write:<br/><br/>$dt-&gt;add( hours =&gt; $expires_days * 24 );<br/><br/><br/>What would happen if duration calculations were always done in UTC?<br/><br/>$tz = $dt-&gt;time_zone;<br/>$dt-&gt;set_time_zone( &#39;UTC&#39; );<br/>$dt += $duration;<br/>$dt-&gt;set_time_zone( $tz );<br/><br/><br/><br/> What advice should I give to our developers about adding durations safely?<br/> It&#39;s a common operaton in our apps.<br/><br/>Thanks,<br/><br/>-- <br/>Bill Moseley<br/>moseley@hank.org<br/><br/> http://www.nntp.perl.org/group/perl.datetime/2013/03/msg7917.html Fri, 08 Mar 2013 04:35:28 +0000 Re: DateTime locale names and wide characters by Dave Rolsky On Fri, 18 Jan 2013, Shane McCarron wrote:<br/><br/>&gt; The @data list is then sorted (by desc) and used to populate a &lt;select&gt;<br/>&gt; element in a web form. Here&#39;s the weird thing. When I am using this under<br/>&gt; Apache on a Linux platform in a CGI application, I get a warning that I am<br/>&gt; printing &#39;wide characters&#39; when I use data from the &#39;desc&#39; as the content<br/>&gt; of an &#39;option&#39; element. What I *think* is that the data coming out of<br/>&gt; DateTime::Locale is not properly encoded as Perl&#39;s utf8 internal encoding.<br/>&gt; If I take the outout of the name() and native_name() methods and encode<br/>&gt; them using &quot;Encode&quot;, then it no longer complains. Is this expected<br/>&gt; behavior?<br/><br/>I think you have the cause a bit backwards.<br/><br/>That warning means that you&#39;re printing data marked as UTF-8 to an output <br/>that expects to receive binary data. By default, all handles expect <br/>binary.<br/><br/>Calling Encode::encode() turns Perl&#39;s UTF-8 flag _off_. I&#39;ve always found <br/>this use of encode (and decode) confusing, since I&#39;d expect encoding to <br/>produce UTF-8, which it does, but it produces _bytes_.<br/><br/>The solution you&#39;re using is probably not the best idea. It&#39;s better to <br/>mark your output filehandle as UTF-8 with binmode() or by passing a layer <br/>to open:<br/><br/> open my $fh, &#39;&gt;:encoding(UTF-8)&#39;, ...;<br/><br/>In a webapp, you&#39;re probably printing to STDOUT so you can use binmode:<br/><br/> binmode STDOUT, &#39;:encoding(UTF-8)&#39;;<br/><br/>I&#39;m not sure how this will interact with mod_perl&#39;s tying of STDOUT, <br/>though.<br/><br/><br/>-dave<br/><br/>/*============================================================<br/>http://VegGuide.org http://blog.urth.org<br/>Your guide to all that&#39;s veg House Absolute(ly Pointless)<br/>============================================================*/<br/> http://www.nntp.perl.org/group/perl.datetime/2013/01/msg7916.html Thu, 31 Jan 2013 02:18:58 +0000 DateTime locale names and wide characters by Shane McCarron I have run into something sort of odd.... I wanted to give users of a web<br/>application a list of date locales to pick from for personalizing their<br/>displays. So I created a hash of mappings from each<br/>DateTime::Locale-&gt;ids() value to the name for each Locale object. The code<br/>looks something like this:<br/><br/> my @data ;<br/><br/> foreach my $id ( DateTime::Locale-&gt;ids() ) {<br/> my $ref = DateTime::Locale-&gt;load( $id ) ;<br/> if ($ref) {<br/> push(@data, { val =&gt; $id, desc =&gt; $ref-&gt;name() } ) ;<br/> }<br/> }<br/><br/>The @data list is then sorted (by desc) and used to populate a &lt;select&gt;<br/>element in a web form. Here&#39;s the weird thing. When I am using this under<br/>Apache on a Linux platform in a CGI application, I get a warning that I am<br/>printing &#39;wide characters&#39; when I use data from the &#39;desc&#39; as the content<br/>of an &#39;option&#39; element. What I *think* is that the data coming out of<br/>DateTime::Locale is not properly encoded as Perl&#39;s utf8 internal encoding.<br/> If I take the outout of the name() and native_name() methods and encode<br/>them using &quot;Encode&quot;, then it no longer complains. Is this expected<br/>behavior?<br/><br/>-- <br/>Shane McCarron<br/>halindrome@gmail.com<br/><br/> http://www.nntp.perl.org/group/perl.datetime/2013/01/msg7915.html Sat, 19 Jan 2013 05:49:52 +0000 Re: The State of the TimeZone in Debian by gregor herrmann On Sat, 22 Dec 2012 22:36:28 +0000, Zefram wrote:<br/><br/>&gt; gregor herrmann wrote:<br/>&gt; &gt;Before I file ITP bugs and upload them, I&#39;d like to have some review;<br/>&gt; I&#39;ll look at them shortly.<br/><br/>Thanks in advance!<br/> <br/>&gt; &gt;What I&#39;m also missing is the big picture how those package relate to<br/>&gt; &gt;the good old DateTime::TimeZone with its tzfiles-converted-to-pm-files.<br/>&gt; &gt;It&#39;s supposed to use Time::OlsonTZ::Data at some point, right?<br/>&gt; Right. There&#39;s a rewrite of DateTime::TimeZone, sitting in my repo,<br/>&gt; that does away with the pm-per-zone modules and uses Time::OlsonTZ::Data<br/>&gt; instead. <br/><br/>Ok, thanks for the confirmation.<br/><br/>&gt; We scheduled the official replacement of DateTime::TimeZone<br/>&gt; for 2012-09-01, but I was out of action for a few months due to a bout<br/>&gt; of depression, so I missed that. I&#39;m picking up the pieces now, and<br/>&gt; we&#39;ll reschedule for some time in 2013.<br/><br/>That&#39;s fine for us; currently we are in release freeze, so I guess<br/>at the time of the switch we&#39;ll be at the early stages of the next<br/>release cycle which is a good date for making the changes.<br/> <br/>&gt; Whereas the current DateTime::TimeZone is volatile, due to including all<br/>&gt; the timezone data, the rewritten DateTime::TimeZone will not be volatile.<br/>&gt; The volatility is being localised in Time::OlsonTZ::Data (and, for you,<br/>&gt; the underlying tzdata package).<br/><br/>Ok.<br/> <br/>&gt; &gt;Do we need something else? I think we can skip<br/>&gt; &gt;Time::OlsonTZ::Download, since we want to use our tzdata anyway,<br/>&gt; &gt;right? And I think App::olson is also not required.<br/>&gt; T:OTZ:Download is a development tool. The build process for T:OTZ:Data<br/>&gt; uses it, even when working from local source, but your modified form<br/>&gt; of T:OTZ:Data build could manage without it <br/><br/>Ok.<br/><br/>&gt; if you tweak the prebuild script a bit. <br/><br/>Actually I&#39;d like to avoid building anything at all and using the<br/>tzfiles from tzdata directly at runtime; but you&#39;ll see this in my<br/>patch and cann tell us if this makes sense :)<br/><br/>&gt; There&#39;s no need for ordinary users to have T:OTZ:Download.<br/><br/>Ok.<br/> <br/>&gt; It would be nice to have App::olson packaged. (Preferably as &quot;olson&quot;<br/>&gt; rather than &quot;libapp-olson-perl&quot;, because it&#39;s intended to be used as<br/>&gt; a command-line program rather than as a Perl module.) It is intended<br/>&gt; for ordinary users. But it&#39;s not necessary to package it at this stage:<br/>&gt; none of the timezone infrastructure depends on it. It is cleanly layered<br/>&gt; on top of Time::OlsonTZ::Data.<br/><br/>Good, let&#39;s keep this in mind for later.<br/><br/><br/>Thanks,<br/>gregor<br/> <br/>-- <br/> .&#39;&#39;`. Homepage: http://info.comodo.priv.at/ - OpenPGP key 0xBB3A68018649AA06<br/> : :&#39; : Debian GNU/Linux user, admin, and developer - http://www.debian.org/<br/> `. `&#39; Member of VIBE!AT &amp; SPI, fellow of the Free Software Foundation Europe<br/> `- NP: Eagles<br/><br/> http://www.nntp.perl.org/group/perl.datetime/2012/12/msg7914.html Mon, 24 Dec 2012 05:40:34 +0000 The State of the TimeZone in Debian by gregor herrmann Following up on<br/><br/>http://lists.alioth.debian.org/pipermail/pkg-perl-maintainers/2012-March/052645.html<br/>and the bug reports<br/>http://bugs.debian.org/660404 and<br/>http://bugs.debian.org/690908<br/><br/>I&#39;ve now looked at some of the mentioned modules, and I&#39;ve created<br/>preliminary packages for<br/><br/>DateTime::TimeZone::Olson / libdatetime-timezone-olson-perl:<br/>http://anonscm.debian.org/gitweb/?p=pkg-perl/packages/libdatetime-timezone-olson-perl.git<br/><br/>Time::OlsonTZ::Data / libtime-olsontz-data-perl:<br/>http://anonscm.debian.org/gitweb/?p=pkg-perl/packages/libtime-olsontz-data-perl.git<br/><br/>Before I file ITP bugs and upload them, I&#39;d like to have some review;<br/>especially on my patch for Time::OlsonTZ::Data, which makes the<br/>module use the tzfiles from tzdata in /usr/share/zoneinfo instead of<br/>duplicating them:<br/>http://anonscm.debian.org/gitweb/?p=pkg-perl/packages/libtime-olsontz-data-perl.git;a=blob;f=debian/patches/tzdata.patch;hb=HEAD<br/>http://anonscm.debian.org/gitweb/?p=pkg-perl/packages/libtime-olsontz-data-perl.git;a=blob;f=debian/rules;hb=HEAD<br/><br/>Besides a general sanity check, some more tests for this patch would<br/>be welcome.<br/><br/>What I&#39;m also missing is the big picture how those package relate to<br/>the good old DateTime::TimeZone with its tzfiles-converted-to-pm-files.<br/>It&#39;s supposed to use Time::OlsonTZ::Data at some point, right?<br/><br/>Do we need something else? I think we can skip<br/>Time::OlsonTZ::Download, since we want to use our tzdata anyway,<br/>right? And I think App::olson is also not required.<br/><br/><br/>Cheers,<br/>gregor<br/><br/>-- <br/> .&#39;&#39;`. Homepage: http://info.comodo.priv.at/ - OpenPGP key 0xBB3A68018649AA06<br/> : :&#39; : Debian GNU/Linux user, admin, and developer - http://www.debian.org/<br/> `. `&#39; Member of VIBE!AT &amp; SPI, fellow of the Free Software Foundation Europe<br/> `- NP: Bettina Wegner: Lied f&uuml;r meine verlassenen Freunde<br/><br/> http://www.nntp.perl.org/group/perl.datetime/2012/12/msg7913.html Sun, 23 Dec 2012 09:09:40 +0000 Re: The State of the TimeZone in Debian by Zefram gregor herrmann wrote:<br/>&gt;Before I file ITP bugs and upload them, I&#39;d like to have some review;<br/><br/>I&#39;ll look at them shortly.<br/><br/>&gt;What I&#39;m also missing is the big picture how those package relate to<br/>&gt;the good old DateTime::TimeZone with its tzfiles-converted-to-pm-files.<br/>&gt;It&#39;s supposed to use Time::OlsonTZ::Data at some point, right?<br/><br/>Right. There&#39;s a rewrite of DateTime::TimeZone, sitting in my repo,<br/>that does away with the pm-per-zone modules and uses Time::OlsonTZ::Data<br/>instead. We scheduled the official replacement of DateTime::TimeZone<br/>for 2012-09-01, but I was out of action for a few months due to a bout<br/>of depression, so I missed that. I&#39;m picking up the pieces now, and<br/>we&#39;ll reschedule for some time in 2013.<br/><br/>Whereas the current DateTime::TimeZone is volatile, due to including all<br/>the timezone data, the rewritten DateTime::TimeZone will not be volatile.<br/>The volatility is being localised in Time::OlsonTZ::Data (and, for you,<br/>the underlying tzdata package).<br/><br/>&gt;Do we need something else? I think we can skip<br/>&gt;Time::OlsonTZ::Download, since we want to use our tzdata anyway,<br/>&gt;right? And I think App::olson is also not required.<br/><br/>T:OTZ:Download is a development tool. The build process for T:OTZ:Data<br/>uses it, even when working from local source, but your modified form<br/>of T:OTZ:Data build could manage without it if you tweak the prebuild<br/>script a bit. There&#39;s no need for ordinary users to have T:OTZ:Download.<br/><br/>It would be nice to have App::olson packaged. (Preferably as &quot;olson&quot;<br/>rather than &quot;libapp-olson-perl&quot;, because it&#39;s intended to be used as<br/>a command-line program rather than as a Perl module.) It is intended<br/>for ordinary users. But it&#39;s not necessary to package it at this stage:<br/>none of the timezone infrastructure depends on it. It is cleanly layered<br/>on top of Time::OlsonTZ::Data.<br/><br/>-zefram<br/> http://www.nntp.perl.org/group/perl.datetime/2012/12/msg7912.html Sat, 22 Dec 2012 22:36:45 +0000 Shutting down the Sourceforge project for the DateTime suite by Dave Rolsky There&#39;s an old SF project that has an SVN repo with many, many DateTime <br/>modules - http://sourceforge.net/projects/perl-date-time<br/><br/>AFAICT, no one is using the the SVN repo any more. The last holdout seemed <br/>to be Flavio Glock, and he just moved his projects to github.<br/><br/>Unless someone objects, I&#39;m going to delete this project at some point in <br/>the next few weeks. I&#39;ll make sure to grab an archive of the SVN repo <br/>before I do that, though.<br/><br/><br/>Dave Rolsky<br/>Compassionate Action for Animals - http://www.exploreveg.org/<br/>VegGuide.Org - http://www.vegguide.org/<br/> http://www.nntp.perl.org/group/perl.datetime/2012/12/msg7911.html Mon, 17 Dec 2012 19:28:35 +0000 Resolving floatting times using a reference time by Olivier Mengué Hi,<br/><br/>I&#39;m writing a Perl application for an embedded system, so I can&#39;t use<br/>DateTime and DateTime::TimeZone modules.<br/>I&#39;m using only the system local timezone and it may have daylight saving<br/>changes.<br/><br/>I need a function that will return an epoch time given a floating date+time<br/>(year, month, day, hour, minute, second) and an absolute epoch time.<br/>Unfortunately Time::Local doesn&#39;t seem to have this feature.<br/><br/>Any suggestion on other modules, or on how to implement this?<br/><br/>Here is below a broken implementation and a test suite with TODOs:<br/><br/>use strict;<br/>use warnings;<br/>use Test::More;<br/><br/>use Time::Local;<br/><br/>sub timelocal_after<br/>{<br/>my ($sec, $min, $hour, $mday, $mon, $year, $after) = @_;<br/> my $time = timelocal($sec, $min, $hour, $mday, $mon, $year);<br/> # FIXME handle ambiguous times correctly<br/> return ($time &gt;= $after) ? $time : undef<br/>}<br/><br/><br/><br/># Dates from 2012-10-28T02:00:00 to (non included) 2012-10-28T03:00:00<br/># are ambiguous<br/>$ENV{TZ} = &#39;Europe/Paris&#39;;<br/><br/># 2012-10-28T01:59:59 =&gt; 2012-10-27T23:59:59Z<br/>is(timelocal_after(59, 59, 1, 28, 9, 112, 1), 1351382399);<br/>is(timelocal_after(59, 59, 1, 28, 9, 112, 1351382399), 1351382399);<br/>is(timelocal_after(59, 59, 1, 28, 9, 112, 1351382399+1), undef);<br/><br/># Resolved to the earlier time<br/># 2012-10-28T02:00:00 =&gt; 2012-10-28T00:00:00Z<br/>is(timelocal_after(0, 0, 2, 28, 9, 112, 1), 1351382400);<br/>is(timelocal_after(0, 0, 2, 28, 9, 112, 1351382400), 1351382400);<br/># Resolved to the later<br/># 2012-10-28T02:00:00 =&gt; 2012-10-28T01:00:00Z<br/>{<br/>local $TODO = &quot;Fix timelocal_after&quot;;<br/>is(timelocal_after(0, 0, 2, 28, 9, 112, 1351382400+1), 1351382400+3600);<br/>is(timelocal_after(0, 0, 2, 28, 9, 112, 1351382400+3600), 1351382400+3600);<br/># Past<br/>is(timelocal_after(0, 0, 2, 28, 9, 112, 1351382400+3601), undef);<br/>}<br/><br/># 2012-10-28T02:59:59 =&gt; 2012-10-28T00:59:59Z<br/>is(timelocal_after(59, 59, 2, 28, 9, 112, 1), 1351385999);<br/>is(timelocal_after(59, 59, 2, 28, 9, 112, 1351382400), 1351385999);<br/>is(timelocal_after(59, 59, 2, 28, 9, 112, 1351385999), 1351385999);<br/># 2012-10-28T02:59:59 =&gt; 2012-10-28T01:59:59Z<br/>{<br/>local $TODO = &quot;Fix timelocal_after&quot;;<br/>is(timelocal_after(59, 59, 2, 28, 9, 112, 1351385999+1), 1351385999+3600);<br/>is(timelocal_after(59, 59, 2, 28, 9, 112, 1351385999+3600),<br/>1351385999+3600);<br/>}<br/>is(timelocal_after(59, 59, 2, 28, 9, 112, 1351385999+3601), undef);<br/><br/><br/># Offset changed to UTC+0100<br/># 2012-10-28T03:00:00 =&gt; 2012-10-28T02:00:00Z<br/>is(timelocal_after(0, 0, 3, 28, 9, 112, 1), 1351385999+3601);<br/><br/>done_testing;<br/><br/> http://www.nntp.perl.org/group/perl.datetime/2012/11/msg7910.html Wed, 28 Nov 2012 11:19:58 +0000 Re: Typo in my patch (not important, but hey) by Dave Rolsky On Mon, 19 Nov 2012, Martin Becker wrote:<br/><br/>&gt; Right after Dave published DateTime-0.78 I spotted a typo in<br/>&gt; the description of a test that was insufficiently updated by<br/>&gt; my patch for rt-79845.<br/><br/>Thanks, I applied this.<br/><br/><br/>-dave<br/><br/>/*============================================================<br/>http://VegGuide.org http://blog.urth.org<br/>Your guide to all that&#39;s veg House Absolute(ly Pointless)<br/>============================================================*/<br/> http://www.nntp.perl.org/group/perl.datetime/2012/11/msg7909.html Tue, 20 Nov 2012 15:02:01 +0000 Typo in my patch (not important, but hey) by Martin Becker <br/>Right after Dave published DateTime-0.78 I spotted a typo in<br/>the description of a test that was insufficiently updated by<br/>my patch for rt-79845.<br/><br/>Sorry!<br/><br/>-Martin<br/><br/><br/>diff -rup DateTime-0.78.orig/t/03components.t DateTime-0.78/t/03components.t<br/>--- DateTime-0.78.orig/t/03components.t 2012-11-16 18:40:40.000000000 +0100<br/>+++ DateTime-0.78/t/03components.t 2012-11-19 14:25:47.000000000 +0100<br/>@@ -260,7 +260,7 @@ is( $monday-&gt;day_of_week, 1, &quot;Monday is<br/> $dt-&gt;set( nanosecond =&gt; 500_000_500 );<br/> <br/> is( $dt-&gt;nanosecond, 500_000_500, &#39;nanosecond is 500,000,500&#39; );<br/>- is( $dt-&gt;microsecond, 500_000, &#39;microsecond is 500,001&#39; );<br/>+ is( $dt-&gt;microsecond, 500_000, &#39;microsecond is 500,000&#39; );<br/> is( $dt-&gt;millisecond, 500, &#39;millisecond is 500&#39; );<br/> <br/> $dt-&gt;set( nanosecond =&gt; 499_999_999 );<br/> http://www.nntp.perl.org/group/perl.datetime/2012/11/msg7908.html Tue, 20 Nov 2012 13:31:51 +0000 Re: Time::OlsonTZ::Data 0.201210 announcement by Bill Moseley On Mon, Nov 12, 2012 at 7:07 PM, Zefram &lt;zefram@fysh.org&gt; wrote:<br/><br/>&gt; Shortly available from all good CPAN mirrors:<br/>&gt;<br/>&gt; file: $CPAN/authors/id/Z/ZE/ZEFRAM/Time-OlsonTZ-Data-0.201210.tar.gz<br/>&gt; size: 592407 bytes<br/>&gt; md5: 138a1802d50d8315475b66f2c9811f0a<br/>&gt;<br/>&gt; Changes from the previous release:<br/>&gt;<br/>&gt; * Olson database version 2012j (code 2012j, data 2012j): 440 canonical<br/>&gt; zones, 142 links<br/>&gt;<br/><br/>Hope this isn&#39;t too dumb of a question, but how does one determine when to<br/>upgrade to these newer modules.<br/><br/>I was wondering about this because I noticed today that some of our<br/>production servers have DateTime from 2009 installed. Although there<br/>doesn&#39;t seem like any significant change in DateTime since then, maybe<br/>DateTime depends on something that does matter.<br/><br/><br/>-- <br/>Bill Moseley<br/>moseley@hank.org<br/><br/> http://www.nntp.perl.org/group/perl.datetime/2012/11/msg7907.html Tue, 13 Nov 2012 08:43:48 +0000 Time::OlsonTZ::Data 0.201210 announcement by Zefram Shortly available from all good CPAN mirrors:<br/><br/> file: $CPAN/authors/id/Z/ZE/ZEFRAM/Time-OlsonTZ-Data-0.201210.tar.gz<br/> size: 592407 bytes<br/> md5: 138a1802d50d8315475b66f2c9811f0a<br/><br/>Changes from the previous release:<br/><br/> * Olson database version 2012j (code 2012j, data 2012j): 440 canonical<br/> zones, 142 links<br/><br/>-zefram<br/> http://www.nntp.perl.org/group/perl.datetime/2012/11/msg7906.html Mon, 12 Nov 2012 19:07:45 +0000 RE: Test issue by Ursetti, Jerry The test passes with perl -w -T t/00-load.pl.<br/><br/>It also passes with &#39;prove&#39;.<br/><br/>I took a guess and removed the -T flag from the test script and &#39;make test&#39; now works. I think Module::Starter puts that into the 00-load.t test by default.<br/><br/>Thanks for your help and sorry to bug you with something that turned out to not be related to DateTime.<br/><br/>Jerry Ursetti<br/> __ __ __ <br/> /_ / | (_ /\/\<br/>/ /__/ _ ) / \<br/>Financial Data Systems and Analytics Management<br/>(805)557-4212 (Work)<br/>(805)732-8484 (Blackberry)<br/><br/><br/>-----Original Message-----<br/>From: Karen Etheridge [mailto:perl@froods.org] <br/>Sent: Thursday, November 08, 2012 9:55 AM<br/>To: datetime@perl.org<br/>Subject: Re: Test issue<br/><br/><br/>&#39;prove&#39; (in all but the most recent releases of Test::Harness - fixed here<br/>- https://github.com/Perl-Toolchain-Gang/Test-Harness/commit/18794a8565633ae08f048b9cf6c25b03be6e1020 ) automatically applies the -w flag to tests, so you can reproduce this error via perl -w t/00-load.t. That will also set you see more output from the test, which will hopefully lead you to the exact problem - something to do with your local timezone settings, as you surmised.<br/><br/><br/>On Thu, Nov 08, 2012 at 05:01:36PM +0000, Ursetti, Jerry wrote:<br/>&gt; When I run &#39;make test&#39;, the test fails with this error:<br/>&gt; <br/>&gt; &#39;Error: Cannot determine local time zone&#39;<br/>&gt; <br/>&gt; If I run the test script directly, &#39;perl -T t/00-load.t&#39;, the test passes.<br/>&gt; <br/>&gt; I tried using the $TZ environment variable (which is set to my time zone of PST8PDT) instead of &#39;local&#39; in MODULE2. That gives me an &#39;Unknown error&#39; with &#39;make test&#39; but it still passes when run directly.<br/><br/><br/><br/><br/>CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is<br/>for the sole use of the intended recipient(s) and may contain confidential<br/>and privileged information or otherwise be protected by law. Any<br/>unauthorized review, use, disclosure or distribution is prohibited. If you<br/>are not the intended recipient, please contact the sender by reply e-mail<br/>and destroy all copies of the original message.<br/><br/><br/><br/><br/>CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information or otherwise protected by law. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. http://www.nntp.perl.org/group/perl.datetime/2012/11/msg7905.html Thu, 08 Nov 2012 10:13:03 +0000 Re: Test issue by Karen Etheridge <br/>&#39;prove&#39; (in all but the most recent releases of Test::Harness - fixed here<br/>- https://github.com/Perl-Toolchain-Gang/Test-Harness/commit/18794a8565633ae08f048b9cf6c25b03be6e1020 )<br/>automatically applies the -w flag to tests, so you can reproduce this error<br/>via perl -w t/00-load.t. That will also set you see more output from the<br/>test, which will hopefully lead you to the exact problem - something to do<br/>with your local timezone settings, as you surmised.<br/><br/><br/>On Thu, Nov 08, 2012 at 05:01:36PM +0000, Ursetti, Jerry wrote:<br/>&gt; When I run &#39;make test&#39;, the test fails with this error:<br/>&gt; <br/>&gt; &#39;Error: Cannot determine local time zone&#39;<br/>&gt; <br/>&gt; If I run the test script directly, &#39;perl -T t/00-load.t&#39;, the test passes.<br/>&gt; <br/>&gt; I tried using the $TZ environment variable (which is set to my time zone of PST8PDT) instead of &#39;local&#39; in MODULE2. That gives me an &#39;Unknown error&#39; with &#39;make test&#39; but it still passes when run directly.<br/><br/><br/> http://www.nntp.perl.org/group/perl.datetime/2012/11/msg7904.html Thu, 08 Nov 2012 09:55:37 +0000 Test issue by Ursetti, Jerry I&#39;ve just run into an odd problem while testing one of my modules that has me stumped. I&#39;m running Perl 5.8.8 on AIX 6.1.<br/><br/>I&#39;m testing a new module that uses one of my other modules. The second module uses the DateTime module and includes code to assign the local timezone to a variable. It sort of works like this:<br/><br/>MyMODULE...<br/>...<br/>Use MODULE2;<br/>Use DateTime;<br/>our $localtz = DateTime::TimeZone-&gt;new( name =&gt; &#39;local&#39; );<br/><br/><br/>I&#39;m having trouble with the most basic test, just trying to use my module:<br/><br/>#!perl -T<br/>use Test::More tests =&gt; 1;<br/>BEGIN {<br/> use_ok( &#39;MyMODULE&#39; );<br/>}<br/>diag( &quot;Testing MyMODULE $ MyMODULE::VERSION, Perl $], $^X&quot; );<br/><br/><br/>When I run &#39;make test&#39;, the test fails with this error:<br/><br/>&#39;Error: Cannot determine local time zone&#39;<br/><br/>If I run the test script directly, &#39;perl -T t/00-load.t&#39;, the test passes.<br/><br/>I tried using the $TZ environment variable (which is set to my time zone of PST8PDT) instead of &#39;local&#39; in MODULE2. That gives me an &#39;Unknown error&#39; with &#39;make test&#39; but it still passes when run directly.<br/><br/>The only way I can get this to work with &#39;make test&#39; is to hardcode the timezone in MODULE2, replacing &#39;local&#39; with &#39;PST8PDT&#39;. I really don&#39;t want to hardcode this.<br/><br/>It seems like somehow the environment isn&#39;t quite right when I run the test via &#39;make test&#39; so when DateTime tries to get the local timezone, it can&#39;t figure it out.<br/><br/>Can I add something to Makefile.PL to make sure the timezone is in the environment? I checked the ExtUtils::MakeMaker pod but didn&#39;t see anything obvious that looked like it would set environment variables. I tried looking at the Test::Harness pod and code but didn&#39;t see anything there that might help explain what was going wrong, either.<br/><br/>Does anyone have any ideas?<br/><br/>Thanks.<br/><br/>Jerry Ursetti<br/> __ __ __<br/> /_ / | (_ /\/\<br/>/ /__/ _ ) / \<br/>Financial Data Systems and Analytics Management<br/>(805)557-4212 (Work)<br/>(805)732-8484 (Blackberry)<br/><br/><br/><br/>CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is<br/>for the sole use of the intended recipient(s) and may contain confidential<br/>and privileged information or otherwise be protected by law. Any<br/>unauthorized review, use, disclosure or distribution is prohibited. If you<br/>are not the intended recipient, please contact the sender by reply e-mail<br/>and destroy all copies of the original message.<br/><br/><br/><br/>CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information or otherwise protected by law. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.<br/> http://www.nntp.perl.org/group/perl.datetime/2012/11/msg7903.html Thu, 08 Nov 2012 09:01:51 +0000 Time::OlsonTZ::Data 0.201209 announcement by Zefram Shortly available from all good CPAN mirrors:<br/><br/> file: $CPAN/authors/id/Z/ZE/ZEFRAM/Time-OlsonTZ-Data-0.201209.tar.gz<br/> size: 593422 bytes<br/> md5: 250e48cb102b840a6c711989260fed53<br/><br/>Changes from the previous release:<br/><br/> * Olson database version 2012i (code 2012i, data 2012i): 440 canonical<br/> zones, 142 links<br/><br/>-zefram<br/> http://www.nntp.perl.org/group/perl.datetime/2012/11/msg7902.html Sat, 03 Nov 2012 14:07:50 +0000 Time::OlsonTZ::Data 0.201208 announcement by Zefram Shortly available from all good CPAN mirrors:<br/><br/> file: $CPAN/authors/id/Z/ZE/ZEFRAM/Time-OlsonTZ-Data-0.201208.tar.gz<br/> size: 592816 bytes<br/> md5: 094b652d130622d0e325fb015f96e256<br/><br/>Changes from the previous release:<br/><br/> * Olson database version 2012h (code 2012h, data 2012h): 440 canonical<br/> zones, 142 links<br/><br/> * in prebuild, handle new location for public domain notice in Olson<br/> tz-link.htm file<br/><br/>-zefram<br/> http://www.nntp.perl.org/group/perl.datetime/2012/11/msg7901.html Thu, 01 Nov 2012 13:07:50 +0000 Re: "The default datetime format for the object’s locale" by Dave Rolsky On Thu, 25 Oct 2012, N Heinrichs wrote:<br/><br/>&gt; If the locale&#39;s definitions for the &#39;medium&#39; formats are<br/>&gt; wrong/outdated (see http://cldr.unicode.org/index/downloads) you could<br/>&gt; propose an update to the locale class itself, but I am unsure of the<br/>&gt; &quot;official&quot; way to do this.<br/><br/>Note that DateTime::Locale is quite behind the CLDR data these days. <br/>Fixing this is kind of a pain in the ass, since the LDML data keeps <br/>changing (sometimes changing internal structure) and the DateTime::Locale <br/>code does a completely half-assed job of parsing the LDML documents.<br/><br/>What I really want to do is write a proper Perl interface to libicu _or_ <br/>reimplement libicu in Perl, but that&#39;s a fairly big project.<br/><br/><br/>-dave<br/><br/>/*============================================================<br/>http://VegGuide.org http://blog.urth.org<br/>Your guide to all that&#39;s veg House Absolute(ly Pointless)<br/>============================================================*/<br/> http://www.nntp.perl.org/group/perl.datetime/2012/10/msg7900.html Thu, 25 Oct 2012 15:16:09 +0000 Re: "The default datetime format for the object’s locale" by N Heinrichs Short answer: As of DateTime v0.72 on my local machine, %c is not<br/>directly configurable.<br/><br/>A little more info:<br/><br/>%c is hardcoded to use the locale&#39;s `datetime_format_default` (search<br/>for &quot;strftime_patterns&quot; in DateTime.pm)<br/><br/>DateTime::Locale::ko does not override &#39;datetime_format_default&#39;. Nor<br/>does it override &#39;default_date_format_length&#39;, or<br/>&#39;default_time_format_length&#39;, both of which default to &#39;medium&#39; (see<br/>DateTime::Locale::root.)<br/><br/>DT:Loc:ko&#39;s &quot;medium&quot; date/time formats are &quot;yyyy\.\ M\.\ d\.&quot; and &quot;a\<br/>h\:mm\:ss&quot;, which is why you get the output below.<br/><br/>So without modifying/overriding DateTime::Locale::ko, or dropping your<br/>use of %c in favor of a custom formatter, it may be difficult to fix<br/>your problem.<br/><br/>If the locale&#39;s definitions for the &#39;medium&#39; formats are<br/>wrong/outdated (see http://cldr.unicode.org/index/downloads) you could<br/>propose an update to the locale class itself, but I am unsure of the<br/>&quot;official&quot; way to do this.<br/><br/>-Nate<br/><br/>On Wed, Oct 24, 2012 at 2:36 AM, Bill Moseley &lt;moseley@hank.org&gt; wrote:<br/>&gt; We have been using formats %c, %x and %X for localizing dates based on<br/>&gt; Locale. Mostly works ok, but for Korean we are getting this:<br/>&gt;<br/>&gt; 2012. 10. 18. &#xC624;&#xD6C4; 4:09:05<br/>&gt;<br/>&gt;<br/>&gt; where (I&#39;ve been told) we would like this format:<br/>&gt;<br/>&gt; 2012&#xB144; 10&#xC6D4; 22&#xC77C; &#xC6D4;&#xC694;&#xC77C; &#xC624;&#xD6C4; 01:44 PDT<br/>&gt;<br/>&gt;<br/>&gt; Is this formatting done in DateTime? I&#39;m wondering how we can set the<br/>&gt; default format used by %c for a given locale.<br/>&gt;<br/>&gt; In a web app what we are currently doing is<br/>&gt; setting DateTime-&gt;DefaultLocale() per request. The DateTime objects are<br/>&gt; inflated from database rows with DBIC.<br/>&gt;<br/>&gt; --<br/>&gt; Bill Moseley<br/>&gt; moseley@hank.org<br/> http://www.nntp.perl.org/group/perl.datetime/2012/10/msg7899.html Wed, 24 Oct 2012 20:59:08 +0000 "The default datetime format for the object’s locale" by Bill Moseley We have been using formats %c, %x and %X for localizing dates based on<br/>Locale. Mostly works ok, but for Korean we are getting this:<br/><br/>2012. 10. 18. &#xC624;&#xD6C4; 4:09:05<br/><br/><br/>where (I&#39;ve been told) we would like this format:<br/><br/>2012&#xB144; 10&#xC6D4; 22&#xC77C; &#xC6D4;&#xC694;&#xC77C; &#xC624;&#xD6C4; 01:44 PDT<br/><br/><br/>Is this formatting done in DateTime? I&#39;m wondering how we can set the<br/>default format used by %c for a given locale.<br/><br/>In a web app what we are currently doing is<br/>setting DateTime-&gt;DefaultLocale() per request. The DateTime objects are<br/>inflated from database rows with DBIC.<br/><br/>-- <br/>Bill Moseley<br/>moseley@hank.org<br/><br/> http://www.nntp.perl.org/group/perl.datetime/2012/10/msg7898.html Tue, 23 Oct 2012 10:37:01 +0000 Time::OlsonTZ::Data 0.201207 announcement by Zefram Shortly available from all good CPAN mirrors:<br/><br/> file: $CPAN/authors/id/Z/ZE/ZEFRAM/Time-OlsonTZ-Data-0.201207.tar.gz<br/> size: 587575 bytes<br/> md5: 659a8598a10f5a51b82d9b01427f4708<br/><br/>Changes from the previous release:<br/><br/> * Olson database version 2012g (code 2012g, data 2012g): 440 canonical<br/> zones, 142 links<br/><br/>-zefram<br/> http://www.nntp.perl.org/group/perl.datetime/2012/10/msg7897.html Wed, 17 Oct 2012 22:07:48 +0000 best way to to make an easy to use "local" DateTime object? by Mark Stosberg <br/>We have a large project that we would like to use our &quot;local&quot; time zone<br/>across many calls to DateTime. We are considering implementing something<br/>like this:<br/><br/>###<br/>package DateTimeX::Local;<br/>use parent &#39;DateTime&#39;;<br/><br/># Calculate and cache the local time zone based on the OS.<br/>our $LocalTZ = DateTime::TimeZone-&gt;new( name =&gt; &#39;local&#39; );<br/><br/>sub new { shift-&gt;SUPER::new( time_zone =&gt; $LocalTZ, @_ ) };<br/>sub now { shift-&gt;SUPER::now( time_zone =&gt; $LocalTZ, @_ ) };<br/>###<br/><br/>This works for us, but there are probably some other places where<br/>&#39;floating&#39; is the default time zone... I see that &#39;floating&#39; is<br/>hard-coded in a few places as the default time zone.<br/><br/>It seems like a useful alternate design might be add this class method:<br/><br/> DateTime-&gt;DefaultTimeZone($tz);<br/><br/>... and refactor to use that instead of the hardcoded value of<br/>&#39;floating&#39; everywhere.<br/><br/>We could then stick a call to DateTime-&gt;DefaultTimeZone somewhere, and<br/>developers could go on using DateTime as usual for the most part.<br/><br/>The problem with the DateTimeX::Local solution is that someone could<br/>slip up and use DateTime directly, and everything would work until...<br/>after 7 or 8pm Eastern Time. :) . Also, the approach would break if a<br/>new location in DateTime was added that also used the &#39;floating&#39; default<br/>as a hard-coded value.<br/><br/>What do you think about the best way to set the time zone to &quot;local&quot;<br/>across a large project?<br/><br/> Mark<br/> http://www.nntp.perl.org/group/perl.datetime/2012/10/msg7896.html Fri, 05 Oct 2012 15:24:38 +0000 Fwd: best way to to make an easy to use "local" DateTime object? by Mark Stosberg <br/>We have a large project that we would like to use our &quot;local&quot; time zone<br/>across many calls to DateTime. We are considering implementing something<br/>like this:<br/><br/>###<br/>package DateTimeX::Local;<br/>use parent &#39;DateTime&#39;;<br/><br/># Calculate and cache the local time zone based on the OS.<br/>our $LocalTZ = DateTime::TimeZone-&gt;new( name =&gt; &#39;local&#39; );<br/><br/>sub new { shift-&gt;SUPER::new( time_zone =&gt; $LocalTZ, @_ ) };<br/>sub now { shift-&gt;SUPER::now( time_zone =&gt; $LocalTZ, @_ ) };<br/>###<br/><br/>This works for us, but there are probably some other places where<br/>&#39;floating&#39; is the default time zone... I see that &#39;floating&#39; is<br/>hard-coded in a few places as the default time zone.<br/><br/>It seems like a useful alternate design might be add this class method:<br/><br/> DateTime-&gt;DefaultTimeZone($tz);<br/><br/>... and refactor to use that instead of the hardcoded value of<br/>&#39;floating&#39; everywhere.<br/><br/>We could then stick a call to DateTime-&gt;DefaultTimeZone somewhere, and<br/>developers could go on using DateTime as usual for the most part.<br/><br/>The problem with the DateTimeX::Local solution is that someone could<br/>slip up and use DateTime directly, and everything would work until...<br/>after 7 or 8pm Eastern Time. :) . Also, the approach would break if a<br/>new location in DateTime was added that also used the &#39;floating&#39; default<br/>as a hard-coded value.<br/><br/>What do you think about the best way to set the time zone to &quot;local&quot;<br/>across a large project?<br/><br/> Mark<br/><br/><br/> http://www.nntp.perl.org/group/perl.datetime/2012/10/msg7895.html Fri, 05 Oct 2012 15:24:36 +0000 Re: best way to to make an easy to use "local" DateTime object? by Zefram Mark Stosberg wrote:<br/>&gt;For a project that does a lot of object creation, I the shorthand could<br/>&gt;still be nice.<br/><br/>It&#39;s very little shortening, and only for that one operation (explicit<br/>construction of a DateTime). Use it in your app if you like, but I<br/>don&#39;t think it&#39;s a candidate for addition to the main DateTime distro.<br/><br/>-zefram<br/> http://www.nntp.perl.org/group/perl.datetime/2012/10/msg7894.html Mon, 01 Oct 2012 09:28:44 +0000 Re: best way to to make an easy to use "local" DateTime object? by Mark Stosberg On 10/01/2012 12:04 PM, Zefram wrote:<br/>&gt; Mark Stosberg wrote:<br/>&gt;&gt; It seems like a useful alternate design might be add this class method:<br/>&gt;&gt;<br/>&gt;&gt; DateTime-&gt;DefaultTimeZone($tz);<br/>&gt; <br/>&gt; That would make the &quot;default timezone&quot; a global variable. If two modules<br/>&gt; in one program both attempt to set it, you lose. If a module sets it<br/>&gt; and the main program also does, you lose. So to be safe, you can never<br/>&gt; set this in a reusable module.<br/>&gt; <br/>&gt; It gets worse. You&#39;re proposing to have this global variable used in<br/>&gt; places that currently use a constant. Effectively, lots of code that<br/>&gt; currently works fine by relying on the constant would now be reading the<br/>&gt; new variable. So if your main program sets the variable to any other<br/>&gt; value, and you&#39;re using any of the modules already on CPAN that rely on<br/>&gt; the current behaviour, you lose.<br/><br/>Thanks for that feedback. You made a good case against this approach.<br/><br/>&gt; Which timezone a particular DateTime object needs is not so much a<br/>&gt; function of the application it&#39;s in, but of the way it&#39;s used in its<br/>&gt; immediate surroundings. There are three main cases, corresponding<br/>&gt; to the timezone designators &quot;UTC&quot; (for an absolute point in time),<br/>&gt; &quot;floating&quot; (for a calendar time in no particular zone), and &quot;local&quot;<br/>&gt; (for describing a point in time to users). A few applications need to<br/>&gt; use multiple local timezones, due to people crossing localities.<br/>&gt; <br/>&gt; Each piece of code that generates DateTime objects should know the<br/>&gt; broad purpose of those objects, and hence which kind of timezone they<br/>&gt; should use. They should generally set the timezone slot explicitly.<br/>&gt; Relying on the &quot;floating&quot; default is acceptable, but being explicit<br/>&gt; about it is better.<br/><br/>So, it sounds like being explicit is the way to go.<br/><br/>The DateTimeX::Local approach would be explicit, while adding another<br/>layer of abstraction. It would be:<br/><br/> DateTimeX::Local-&gt;new;<br/><br/>vs:<br/><br/> DateTime-&gt;new( time_zone =&gt; &#39;local&#39; );<br/><br/>For a project that does a lot of object creation, I the shorthand could<br/>still be nice.<br/><br/> Mark<br/> http://www.nntp.perl.org/group/perl.datetime/2012/10/msg7893.html Mon, 01 Oct 2012 09:20:17 +0000