Re: Serious Problem - DateTime::Timezone 0.89 when set to Africa / Cairo throws exception right now

2009-04-24 Thread Tatsuhiko Miyagawa
I believe it has something to do with the fact that Cairo is
transitioning to Daylight Savings today.

On Fri, Apr 24, 2009 at 11:31 PM, Shane McCarron  wrote:
> Actually, I was wrong - this is a call to DateTime->today.  As in:
>
> my $d = DateTime->today(time_zone => "Africa/Cairo") ;
>
> This is failing with the exception below.  Help?
>
> Shane McCarron wrote:
>>
>> Right now (seconds since the epoch 1240582619 more or less) if I attempt
>> to create a datetime object using that value in the Afirca / Caori timezone,
>> I am getting an exception:
>>
>> //Invalid local time for date in time zone: Africa/Cairo
>>
>> Stack:
>>  [C:\Perl\site\lib\DateTime\TimeZone.pm:209]
>>  [C:\Perl\site\lib\DateTime\TimeZone.pm:164]
>>  [C:\Perl\site\lib\DateTime.pm:870]
>>  [C:\Perl\site\lib\DateTime.pm:335]
>>  [C:\Perl\site\lib\DateTime.pm:215]
>>  [C:\Perl\site\lib\DateTime.pm:250]
>>  [C:\Perl\site\lib\DateTime.pm:1824]
>>  [C:\Perl\site\lib\DateTime.pm:477]
>> //
>>
>>
>> I have a customer who is down because of this.  Any suggestions?
>>
>
> --
> Shane P. McCarron                          Phone: +1 763 786-8160 x120
> Managing Director                            Fax: +1 763 786-8180
> ApTest Minnesota                            Inet: sh...@aptest.com
>
>
>



-- 
Tatsuhiko Miyagawa


Re: Letting users select timezone

2009-01-21 Thread Tatsuhiko Miyagawa
On Wed, Jan 21, 2009 at 3:03 AM, David Cantrell
 wrote:
> Tatsuhiko Miyagawa wrote:
>
>> You can get the user's country ... from Accept-Language HTTP header
>
> No you can't.  I prefer to use English (specifically en-gb) whether I'm in
> the UK, Germany or Japan.  Even if I were to move to Japan permanently, I'd
> still prefer to use English, and so leave that header set to en-gb, but
> would also like sites to know that I'm in the Asia/Tokyo timezone.

Don't cut-quote my original message.

You can get the user's country using their preference, or from
Accept-Language HTTP header or using IP-to-geo mapping. If
Accept-Language header only contains the language not country (like
en, instead of en_gb), or that doesn't match with the country you can
guess from IP, you can dislpay both.

I know I'm not suggesting the solution that works for 100% of
situations, if the user wants to get the explicit list of all
timezones, you could always display them all with the checkbox or
something (like you can see on google calendar).

> Or consider that French is used not just in mainland France, but also in St
> Pierre (off the Canadian coast), a load of places in the Caribbean, and the
> Indian and Pacific oceans.

In an ideal world when a Canadian people uses French, the HTTP-Accept
header value would be fr_ca, instead of just fr. But even if it's just
'fr', wr can go back to the previous paragraph.

-- 
Tatsuhiko Miyagawa


Re: Letting users select timezone

2009-01-20 Thread Tatsuhiko Miyagawa
On Tue, Jan 20, 2009 at 3:02 AM, David Cantrell
 wrote:

> From a practical point of view, you probably want users to select first from
> a list of areas (eg Europe, or Africa) and then a city within that area, to
> avoid having a very long list.  Even sorted alphabetically, a long list can
> be a pain from an accessibility point of view.

You can get the user's country using their preference, or from
Accept-Language HTTP header or using IP-to-geo mapping and then use
DateTime::TimeZone->names_in_country($cc) to get the list of available
TZ names.

-- 
Tatsuhiko Miyagawa


Re: DateTime::Lite

2008-11-23 Thread Tatsuhiko Miyagawa
On Sun, Nov 23, 2008 at 9:45 AM, Alex Teslik <[EMAIL PROTECTED]> wrote:
>
> Your goals are clear. I welcome a DateTime::Lite pure Perl module that covers
> the basic needs of DateTime manipulation with minimal overhead. I don't expect
> full compatibility - hence the "Lite".

+1.

I have lots of mostly command line scripts that use DateTime solely to
print the current time etc. and have had to convert to something else
when asked to make it portable or run with less memory etc. It'll be
extremely useful if we can start writing code with DateTime and later
replace the 'use' line with DateTime::Lite, or start writing with
DateTime::Lite and later "upgrade" to DateTime when we need more
complex stuff like Set or Calendar APIs.


-- 
Tatsuhiko Miyagawa


Re: DateTime speed differences between perl 5.80 and 5.8.8?

2008-08-12 Thread Tatsuhiko Miyagawa
On Tue, Aug 12, 2008 at 3:52 PM, Tatsuhiko Miyagawa <[EMAIL PROTECTED]> wrote:
> This sounds like RedHat perl's nasty patch to make bless() slow in a
> package with overloads.
> https://bugzilla.redhat.com/show_bug.cgi?id=196836
>
> Upgrading perl RPM to 5.8.23 or later should fix the problem.

I meant 5.8.8-23, obviously.

--
Tatsuhiko Miyagawa


Re: DateTime speed differences between perl 5.80 and 5.8.8?

2008-08-12 Thread Tatsuhiko Miyagawa
This sounds like RedHat perl's nasty patch to make bless() slow in a
package with overloads.
https://bugzilla.redhat.com/show_bug.cgi?id=196836

Upgrading perl RPM to 5.8.23 or later should fix the problem.

On Tue, Aug 12, 2008 at 3:38 PM, Erasmus Oblar <[EMAIL PROTECTED]> wrote:
> I'm seeing some major performance differences between running DateTime on a
> redhat 3 vs redhat 5 system.
...
> Everything looks reasonable between the two machines, except for the *69
> seconds* taken by  machine B in DateTime->new line 181.
>
> Did something change regarding how expensive bless is in perl 5.8.0 vs
> .5.8.8?
>
> Is there a better way for this code to be written?  Any help would be much
> appreciated.  If you'd like any other details, please let me know.
>
> cheers,
> E
>



-- 
Tatsuhiko Miyagawa


Re: Daylight savings time timezone conversion automatically?

2008-03-26 Thread Tatsuhiko Miyagawa
On Wed, Mar 26, 2008 at 11:34 AM, Ewald Beekman <[EMAIL PROTECTED]> wrote:
> Is there a way to see if DST is in effect on a
>  returned time zone object ?
>  For instance, i have got a loop like this:
>
>  my @list = DateTime::TimeZone->all_names;
>  foreach $zone (@list) {
> next unless ($zone =~ /\//);# skip timezone links 
> in the list
> $dt = DateTime->now();  # current computer 
> time
> $tz = DateTime::TimeZone->new( name => $zone ); # timezone
>
> $offset = $tz->offset_for_datetime($dt);# offset from UTC for 
> this timezone
> $TZ = $tz->short_name_for_datetime($dt);# timezone name (e.g. 
> CET)
> $dt->add(seconds =>  $offset);  # convert computer 
> time to time in timezone
> $hoffset = $offset / 3600;  # offset in hours
>
> printf "%40s\t%s\tGMT diff = %g\t%4s\t",$zone,$TZ, $hoffset,$DST;
> printf "%d/%02d/%02d 
> %02d:%02d\n",$dt->year,$dt->month,$dt->day,$dt->hour,$dt->minute;
> }
>
>  How can i see for each zone displayed if it is in DST?

is_dst() method does it for you.

  if ($dt->clone->set_time_zone($tz)->is_dst) {
   # it's in DST now
  }

HTH


Re: DateTime 5-year anniversary

2008-01-15 Thread Tatsuhiko Miyagawa
Happy Birthday! Here's my gift:
http://use.perl.org/~miyagawa/journal/35396

  use Acme::DateTime::Duration::Numeric;
  my $birthday = 5->years->ago;

On 1/15/08, Dave Rolsky <[EMAIL PROTECTED]> wrote:
> Well, I kind of missed it, as it was January 9th. I've been reading my old
> use Perl journal posts and that led me to the post that basically started
> the Perl DateTime project back in 2003 -
> http://www.nntp.perl.org/group/perl.datetime/2003/01/msg388.html
>
> Thanks to everyone who's contributed over the years. I don't think we
> realized that we'd end up creating _the_ definitive set of Perl date/time
> libraries, to the point where a _lot_ of people say "oh, I just use
> DateTime for everything".
>
> Even better, I think we still have one of the best date/time library
> suites of _any_ language out there. The only thing I've seen in all this
> time that comes close is the Chronos library for Smalltalk, myself.
>
>
> -dave
>
> /*===
> VegGuide.Orgwww.BookIRead.com
> Your guide to all that's veg.   My book blog
> ===*/
>


-- 
Tatsuhiko Miyagawa


[PATCH] is DST or isn't

2007-09-21 Thread Tatsuhiko Miyagawa
I was reading through the subtraction section of DateTime POD and it
was a bit confusing because the comment "is DST" and "not DST" for the
$dt objects are all wrong. Attached is a patch to fix this.

-- 
Tatsuhiko Miyagawa
Index: lib/DateTime.pm
===
--- lib/DateTime.pm (revision 3768)
+++ lib/DateTime.pm (working copy)
@@ -2841,12 +2841,12 @@
 my $dt1 = DateTime->new( year => 2003, month => 5, day => 6,
  time_zone => 'America/Chicago',
);
-# not DST
+# is DST

 my $dt2 = DateTime->new( year => 2003, month => 11, day => 6,
  time_zone => 'America/Chicago',
);
-# is DST
+# not DST

 my $dur = $dt2->subtract_datetime($dt1);
 # 6 months
@@ -2859,13 +2859,13 @@
  hour => 1, minute => 58,
  time_zone => "America/Chicago",
);
-# is DST
+# not DST

 my $dt2 = DateTime->new( year => 2003, month => 4, day => 7,
  hour => 2, minute => 1,
  time_zone => "America/Chicago",
);
-# not DST
+# is DST

 my $dur = $dt2->subtract_datetime($dt1);
 # 2 days and 3 minutes
@@ -2877,13 +2877,13 @@
  hour => 1, minute => 58,
  time_zone => "America/Chicago",
);
-# is DST
+# not DST

 my $dt2 = DateTime->new( year => 2003, month => 4, day => 6,
  hour => 3, minute => 1,
  time_zone => "America/Chicago",
);
-# not DST
+# is DST

 my $dur = $dt2->subtract_datetime($dt1);
 # 1 day and 3 minutes

Re: DateTime::Locale encoding

2007-08-07 Thread Tatsuhiko Miyagawa
On 8/7/07, Tobias Kremer <[EMAIL PROTECTED]> wrote:
> Might be the case. But I really like to understand what is causing this
> problem instead of just working around it with some plugins.

understood.

>  The saying
> goes that if you keep everything utf8-encoded you don't have to worry
> much
> about encoding. In this case apparently everything _IS_ utf8 encoded but
> nevertheless it breaks for certain parts.

utf8 encoded and utf8-flagged are a different thing, at least in Perl.
manpages of encoding::warnings or perlunitut (included in perl 5.9.x)
would be helpful to understand the problem.




-- 
Tatsuhiko Miyagawa


Re: DateTime::Locale encoding

2007-08-07 Thread Tatsuhiko Miyagawa
Using Template::Provider::Encoding + Template::Stash::ForceUTF8 is one
way to avoid these annoying utf-8 bytes vs. Unicode string woes.

On 8/7/07, Tobias Kremer <[EMAIL PROTECTED]> wrote:
> Am 07.08.2007 um 18:40 schrieb Bill Moseley:
> > Look at the source of Template::Provider.  If set it assumes the text
> > of the template is utf8 and decodes it.
> > But if your problem is displaying variables (not templates) that are
> > utf8 then sounds like something else.
>
> Exactly. utf8-encoded text in the templates is displayed correctly.
> Other
> stuff coming in from the stash that is utf8-encoded works perfectly,
> too.
>
> > Are you using the Unicode::Encoding plugin in your Catalyst
> > application?
>
> No. This happens even with no plugins loaded at all. You can try it
> out just by adding the following line to one of your controllers
> and putting [% monthnames %] in the TT template:
>
> $c->stash->{'monthnames'} = join ",", @{ DateTime::Locale->load('de')-
>  >month_names };
>

-- 
Tatsuhiko Miyagawa


memory leaks in DateTime?

2006-11-18 Thread Tatsuhiko Miyagawa

I guess this is somewhat related to the STORABLE problem I sent in the
previous email, but run cpan> install DateTime::Format::Japanese (or
whatever Calendar related modules) would cause lots of:

 Attempt to free unreferenced scalar: SV 0x8a56848 during global destruction.


--
Tatsuhiko Miyagawa


[PATCH] DateTime::Locale object is not properly serialized

2006-11-18 Thread Tatsuhiko Miyagawa

Here's a patch against DateTime 0.34, which causes problems
serializing DateTime:Locale object.

For whatever reason I don't know, STORABLE_thaw receives $locale
object as a plain blessed hash, like

 bless( {}, 'DateTime::Locale::de' );

and fails with subsequent calls to the locale object, for example when
you double serialize the object again. It causes make test failures in
DateTime::Util::Astro for instance.

I added a hack to grab class name (de) and calls
DateTime::Locale->load again to get the full object back.


--
Tatsuhiko Miyagawa


DateTime-0.34-locale-storable.patch
Description: Binary data


Re: ANNOUNCE: DateTime::TimeZone 0.52

2006-11-10 Thread Tatsuhiko Miyagawa

On 10/23/06, Dave Rolsky <[EMAIL PROTECTED]> wrote:

0.52 2006-10-22

- The names_in_country() method no longer sorts the zone
  names. Instead, it returns them in order from most- to
  least-populated.


In 0.55 it's still sorted by names.

% perl -MDateTime::TimeZone -le 'print $DateTime::TimeZone::VERSION;
print [ DateTime::TimeZone->names_in_country("us") ]->[0]'
0.55
America/Adak

In 0.52 you removed the sort() in the wrong place. Here's a patch and
an unit test against 0.55.

=== t/15catalog.t
==
--- t/15catalog.t   (revision 5779)
+++ t/15catalog.t   (local)
@@ -8,7 +8,7 @@
use DateTime::TimeZoneCatalog;


-plan tests => 29;
+plan tests => 30;

{
my @all = DateTime::TimeZone::all_names();
@@ -100,3 +100,10 @@
   [ 'America/Santiago', 'Pacific/Easter' ],
   'zones for Chile are America/Santiago and Pacific/Easter' );
}
+
+{
+my @zones = DateTime::TimeZone::names_in_country('us');
+is( $zones[0], 'America/New_York', 'I <3 New York' );
+}
+
+
=== tools/parse_olson
==
--- tools/parse_olson   (revision 5779)
+++ tools/parse_olson   (local)
@@ -431,12 +431,12 @@
$countries{UK} = $countries{GB};

my $countries = '';
-# We explicitly do not sort these because the order in zones.tab
-# is by population.
-for my $c ( keys %countries )
+for my $c ( sort keys %countries )
{
$countries .= qq|  '\L$c' => [ qw(\n|;
-$countries .= join "\n", map { "$_" } sort @{ $countries{$c} };
+# We explicitly do not sort these because the order in zones.tab
+    # is by population.
+$countries .= join "\n", map { "$_" } @{ $countries{$c} };
$countries .= "\n) ],\n";
}


--
Tatsuhiko Miyagawa


Re: patches for DateTime::TimeZone 0.46

2006-11-09 Thread Tatsuhiko Miyagawa

Sorry to bring up a really old thread, but this problem started to
annoy Win32 users of my software (DateTime::TimeZone->new('local')
dies with "Cannot determin local timezone even with TZ=JST-9 correctly
set)

On 8/7/06, Dave Rolsky <[EMAIL PROTECTED]> wrote:

> Hi, with these patches, DateTime::TimeZone->new('local')
> will work properly under the cirtcumstances with TZ=JST-9
> (common setting in Japan, means TZ=+0900).

If JST-9 is a common time zone, I'd think the simplest thing would be to
just add it to the list of links in DateTime::TimeZoneCatalog, and link it
to the Asia/Japan zone. Of course, then it'd have the same DST rules as
that zone, which may not be what you want.


We don' t have DST here and there's no problem. Actaully now I can see
JST-9 in LINKS of TimeZoneCatalog.pm. The only fix we need is to allow
"JST-9" in _could_be_valid_time_zone() as patched by Kenichi.

I guess the regexp can be tighten up like,

 return $_[0] =~ m,^[\w/]+(?:\+\-\d)?$, ? 1 : 0;

though.

==
diff -ru DateTime-TimeZone-0.46/lib/DateTime/TimeZone/Local.pm
DateTime-TimeZone-0.46-patched/lib/DateTime/TimeZone/Local.pm
--- DateTime-TimeZone-0.46/lib/DateTime/TimeZone/Local.pm   2006-05-09
06:42:05.0 +0900
+++ DateTime-TimeZone-0.46-patched/lib/DateTime/TimeZone/Local.pm
2006-07-30
03:12:25.186375000 +0900
@@ -228,7 +228,10 @@
   return 0 unless defined $_[0];
   return 0 if $_[0] eq 'local';

-return $_[0] =~ m,^[\w/]+$, ? 1 : 0;
+return 1 if $_[0] =~ m,^[\w/]+$,;
+return 1 if $_[0] =~ m,^\w+\s*[\+\-]\s*\d+$,;
+
+return 0;
}



Thanks!

--
Tatsuhiko Miyagawa


Re: ANN: DateTime::Span::Birth

2006-10-25 Thread Tatsuhiko Miyagawa

I picked the name to keep sync with Date::Range::Birth, but Birthdate
was another candidate. I wouldn't mind renaming the module to increase
my CPAN distro count :)

On 10/26/06, Dave Rolsky <[EMAIL PROTECTED]> wrote:

On Thu, 26 Oct 2006, Tatsuhiko Miyagawa wrote:

> DateTime::Span::Birth 0.01 is now going to CPAN.

A nit on the name. With just "birth", it seems like it might be related to
predicting the birth of a baby, something like generating a span of dates
in which the birth is expected. I think it might be better named
::Birthdate.


--
Tatsuhiko Miyagawa


ANN: DateTime::Span::Birth

2006-10-25 Thread Tatsuhiko Miyagawa

DateTime::Span::Birth 0.01 is now going to CPAN.

This module is a port of Date::Range::Birth, which allows you to build
a range of dates for birthdays of people with particular age. This
makes it easy for you to build an SQL query for example, to select
teenager users from your database which has 'birth' column as
datetime.

 # build a datetime span for teenagers
 use DateTime::Span::Birth;
 my $span = DateTime::Span::Birth->new(from => 13, to => 19);

 # build an SQL query in a raw way
 my $sql = "SELECT * FROM user WHERE birthday >= ? AND birthdy <= ?"

 my $sth = $dbh->prepare($sql);
 $sth->execute($span->start->ymd, $span->end->ymd);

The code is also available in my subversion repository:
http://svn.bulknews.net/repos/public/DateTime-Span-Birth/trunk/

--
Tatsuhiko Miyagawa


Re: parenthesis in DateTime::Format::Strptime

2006-10-25 Thread Tatsuhiko Miyagawa

Hm, you might want to make it backward compatible, not to escape them
if it's already escaped.

=== lib/DateTime/Format/Strptime.pm
==
--- lib/DateTime/Format/Strptime.pm (revision 5695)
+++ lib/DateTime/Format/Strptime.pm (local)
@@ -582,6 +582,7 @@
   my @fields = $field_list =~ m/(%\{\w+\}|%\d*.)/g;
   $field_list = join('',@fields);

+$regex =~ s/(?now(); # Created just so we can do
$tempdt->can(..)

   # Locale-ize the parser
=== t/008_parens.t
==
--- t/008_parens.t  (revision 5695)
+++ t/008_parens.t  (local)
@@ -0,0 +1,12 @@
+use strict;
+use warnings;
+use Test::More;
+use DateTime::Format::Strptime;
+
+plan tests => 1;
+
+{
+my $str = "2006/10/25 (Wed)";
+my $p   = DateTime::Format::Strptime->new(pattern => "%Y/%m/%d (%a)");
+ok my $dt  = $p->parse_datetime($str);
+}



On 10/25/06, Tatsuhiko Miyagawa <[EMAIL PROTECTED]> wrote:

Here's a patch for DateTime::Format::Strptime, to allow parsing
strings like "2006/10/25 (Wed)" without the kludge to escape
parenthesis in the format.


=== lib/DateTime/Format/Strptime.pm
==
--- lib/DateTime/Format/Strptime.pm (revision 5695)
+++ lib/DateTime/Format/Strptime.pm (local)
@@ -582,6 +582,7 @@
   my @fields = $field_list =~ m/(%\{\w+\}|%\d*.)/g;
   $field_list = join('',@fields);

+$regex =~ s/([\(\)])/\\$1/g;  # escape parens
   my $tempdt = DateTime->now(); # Created just so we can do
$tempdt->can(..)

   # Locale-ize the parser
=== t/008_parens.t
==
--- t/008_parens.t  (revision 5695)
+++ t/008_parens.t  (local)
@@ -0,0 +1,12 @@
+use strict;
+use warnings;
+use Test::More;
+use DateTime::Format::Strptime;
+
+plan tests => 1;
+
+{
+my $str = "2006/10/25 (Wed)";
+my $p   = DateTime::Format::Strptime->new(pattern => "%Y/%m/%d (%a)");
+ok my $dt  = $p->parse_datetime($str);
+}



--
Tatsuhiko Miyagawa




--
Tatsuhiko Miyagawa


parenthesis in DateTime::Format::Strptime

2006-10-24 Thread Tatsuhiko Miyagawa

Here's a patch for DateTime::Format::Strptime, to allow parsing
strings like "2006/10/25 (Wed)" without the kludge to escape
parenthesis in the format.


=== lib/DateTime/Format/Strptime.pm
==
--- lib/DateTime/Format/Strptime.pm (revision 5695)
+++ lib/DateTime/Format/Strptime.pm (local)
@@ -582,6 +582,7 @@
   my @fields = $field_list =~ m/(%\{\w+\}|%\d*.)/g;
   $field_list = join('',@fields);

+$regex =~ s/([\(\)])/\\$1/g;  # escape parens
   my $tempdt = DateTime->now(); # Created just so we can do
$tempdt->can(..)

   # Locale-ize the parser
=== t/008_parens.t
==
--- t/008_parens.t  (revision 5695)
+++ t/008_parens.t  (local)
@@ -0,0 +1,12 @@
+use strict;
+use warnings;
+use Test::More;
+use DateTime::Format::Strptime;
+
+plan tests => 1;
+
+{
+my $str = "2006/10/25 (Wed)";
+my $p   = DateTime::Format::Strptime->new(pattern => "%Y/%m/%d (%a)");
+    ok my $dt  = $p->parse_datetime($str);
+}



--
Tatsuhiko Miyagawa


Re: ANNOUNCE: DateTime::TimeZone 0.53

2006-10-24 Thread Tatsuhiko Miyagawa

Looks like OffsetOnly is not thawed correctly, hence W3CDTF formatter
(for instance) doesn't work with dclone'd object.

use strict;
use warnings;
use DateTime::TimeZone;
use DateTime::Format::W3CDTF;
use Storable;
use Test::More 'no_plan';
use YAML;

{
   my $dt = DateTime->now(time_zone => '+0900');
   my $clone = Storable::dclone($dt);
   my $w3cdtf  = DateTime::Format::W3CDTF->new->format_datetime($dt);
   my $w3cdtf2 =  DateTime::Format::W3CDTF->new->format_datetime($clone);
   is $w3cdtf, $w3cdtf2;
   is Dump($dt), Dump($clone);
}


On 10/25/06, Tatsuhiko Miyagawa <[EMAIL PROTECTED]> wrote:

Looks like this broke t/23storable.t of the current DateTime.

rock:/usr/local/src/CPAN/build/DateTime-0.35# prove -lv t/23storable.t
t/23storable1..16
Can't use an undefined value as an ARRAY reference at
/usr/local/share/perl/5.8.4/DateTime/TimeZone.pm line 172, at
t/23storable.t line 31
# Looks like your test died before it could output anything.
dubious
   Test returned status 255 (wstat 65280, 0xff00)
DIED. FAILED tests 1-16
   Failed 16/16 tests, 0.00% okay
Failed TestStat Wstat Total Fail  List of Failed
---
t/23storable.t  255 6528016   32  1-16
Failed 1/1 test scripts. 16/16 subtests failed.
Files=1, Tests=16,  0 wallclock secs ( 0.33 cusr +  0.05 csys =  0.38 CPU)
Failed 1/1 test programs. 16/16 subtests failed.



On 10/25/06, Dave Rolsky <[EMAIL PROTECTED]> wrote:
> 0.53 2006-10-24
>
> - Freezing and thawing a DT::TimeZone::OffsetOnly object was broken in
>   0.52 (and probably earlier versions as well). Reported by Tatsuhiko
>   Miyagawa.

I'm sure freezing/thawing of DT::TZ::OffsetOnly was NOT broken in
earlier versions than 0.52, since our app started to break after
upgrading to 0.52.


--
Tatsuhiko Miyagawa




--
Tatsuhiko Miyagawa


Re: ANNOUNCE: DateTime::TimeZone 0.53

2006-10-24 Thread Tatsuhiko Miyagawa

Looks like this broke t/23storable.t of the current DateTime.

rock:/usr/local/src/CPAN/build/DateTime-0.35# prove -lv t/23storable.t
t/23storable1..16
Can't use an undefined value as an ARRAY reference at
/usr/local/share/perl/5.8.4/DateTime/TimeZone.pm line 172, at
t/23storable.t line 31
# Looks like your test died before it could output anything.
dubious
   Test returned status 255 (wstat 65280, 0xff00)
DIED. FAILED tests 1-16
   Failed 16/16 tests, 0.00% okay
Failed TestStat Wstat Total Fail  List of Failed
---
t/23storable.t  255 6528016   32  1-16
Failed 1/1 test scripts. 16/16 subtests failed.
Files=1, Tests=16,  0 wallclock secs ( 0.33 cusr +  0.05 csys =  0.38 CPU)
Failed 1/1 test programs. 16/16 subtests failed.



On 10/25/06, Dave Rolsky <[EMAIL PROTECTED]> wrote:

0.53 2006-10-24

- Freezing and thawing a DT::TimeZone::OffsetOnly object was broken in
  0.52 (and probably earlier versions as well). Reported by Tatsuhiko
  Miyagawa.


I'm sure freezing/thawing of DT::TZ::OffsetOnly was NOT broken in
earlier versions than 0.52, since our app started to break after
upgrading to 0.52.


--
Tatsuhiko Miyagawa


[bug] DateTime::TimeZone::OffsetOnly and Storable

2006-10-24 Thread Tatsuhiko Miyagawa

Hi,

DateTime::TimeZone 0.52 broke Storable::dclone'ing of DT::TZ::OffsetOnly object.

#!/usr/bin/perl
use strict;
use warnings;
use DateTime::TimeZone;
use Storable;

my $dt = DateTime::TimeZone->new( name => '-0300' );
Storable::dclone($dt);

Run this code and you'll get the following error:

The following parameter was passed in the call to
DateTime::TimeZone::OffsetOnly::new but was not listed in the
validation options: name

I believe this didn't happen with versions earlier than 0.51.


--
Tatsuhiko Miyagawa


DateTime::TimeZone functions

2006-10-13 Thread Tatsuhiko Miyagawa

Hi, DT::TZ doc says:

=head2 Other Functions

This class also contains several functions, none of which are
exported.  Calling these as class methods will also work.

=over 4
=item * offset_as_seconds( $offset )
...
=item * offset_as_string( $offset )
...
=back

But none of those offset_as_* methods doesn't work as class methods.
Need to update either docs or the code.

--
Tatsuhiko Miyagawa


Re: DateTime::TimeZone::FromCountry

2006-10-13 Thread Tatsuhiko Miyagawa

On 10/14/06, Dave Rolsky <[EMAIL PROTECTED]> wrote:

This is in 0.51. It's a bit different from what you wrote. The biggest
difference is that you can only get the zones by country code. I didn't
want to add a dependency on Locale::Country, but I did mention it in the
docs.


Looks like you sort the names per country, but the zone.tab file has a
meaning in its order, which is quite useful. Quote,

 # The table is sorted first by country, then an order within the country that
 # (1) makes some geographical sense, and
 # (2) puts the most populous zones first, where that does not contradict (1).

So, names_in_country('US')->[0] would be better 'America/New_York'
instead of 'America/Adak', and names_in_country('CN')->[0] would be
better 'Asia/Shanghai' instead of 'Asia/Chongqing'.

If users want the sorted list, we can just do

 @names = sort DateTime::TimeZone->names_in_country('US');

Can you remove the 'sort' from the following code in parse_olson?

   $countries .= join "\n", map { "$_" } sort @{ $countries{$c} };

Thanks,

--
Tatsuhiko Miyagawa


Re: DateTime::TimeZone::FromCountry

2006-10-13 Thread Tatsuhiko Miyagawa

On 10/14/06, Dave Rolsky <[EMAIL PROTECTED]> wrote:


This is in 0.51. It's a bit different from what you wrote. The biggest
difference is that you can only get the zones by country code. I didn't
want to add a dependency on Locale::Country, but I did mention it in the
docs.


Understood. Well, actually you don't need to depend on Locale::Country
since there's "iso3166.tab" file in the Olson tarball to map a full
country name to iso 3166 code. Not sure this is totally necessary, but
it's just another 244 lines of data :)

Thanks for including this in DateTime::TimeZone anyway, this quickly!

--
Tatsuhiko Miyagawa


Re: DateTime::TimeZone::FromCountry

2006-10-13 Thread Tatsuhiko Miyagawa

On 10/14/06, Dave Rolsky <[EMAIL PROTECTED]> wrote:


Given that it's created from the Olson data, I think it belongs as part of
the core DT::TZ distro. Right now, whenever a new Olson tarball is
released, I have an automated script to grab it and regen DT::TZ, so
adding this should be pretty trivial.


Actually my module (FromCountry/Zone.pm) is also auto-generated from
Olson tarball using tools/create_zone_pm.pl in the SVN repository.


I'll take a look at the tarball and integrate it into the DT::TZ.
I'll probably change the package name so it's just part of DT::TZ, which
already has a bunch of functions for getting lists of time zones.


Sounds great. Thanks!

--
Tatsuhiko Miyagawa


DateTime::TimeZone::FromCountry

2006-10-13 Thread Tatsuhiko Miyagawa

Per demands[1] to get the list of available timezones from
$country_code, I created a simple module
DateTime::TimeZone::FromCountry, available at:
http://svn.bulknews.net/repos/public/DateTime-TimeZone-FromCountry/trunk/

What this module does is very simple:

 use DateTime::TimeZone;
 use DateTime::TimeZone::FromCountry;

 my $time_zone = DateTime::TimeZone->from_country('JP');#
Asia/Tokyo
 my @time_zone = DateTime::TimeZone->from_country('US');#
List of possible TZs
 my $time_zone = DateTime::TimeZone->from_country('United States'); #
America/New_York

the actual mapping data (from country to available timezones) is
created using 'zone.tab' file in the Olson database.

Dave: Do you think it's OK to upload this module to CPAN? Or, should
it be part of DateTime::TimeZone module itself?

I guess this module might have to be synchronized to
DateTime::TimeZone anyway as Olson gets updated, so including it as
part of DT::TZ would be nice.

[1] See http://use.perl.org/~miyagawa/journal/31310 for the motivation
and probable use case of this module.

--
Tatsuhiko Miyagawa


Re: [use Perl] New Journal Entry by Alias, "Request for Volunteers: DateTime::Cron::Simple Replacement"

2006-09-29 Thread Tatsuhiko Miyagawa

On 9/30/06, Adriano Ferreira <[EMAIL PROTECTED]> wrote:


The main point is the 'validate_time' method. What does it do? Verify
that a date matches the specification given by the cron entry. Just
this.

  '2009-09-01T00:00:00' matches '* * * * *'
  '2009-09-01T00:00:00' matches '0 * * * *'
  '2009-09-01T00:01:00' does not matches '0 * * * *'
  '2009-09-01T00:00:00' matches '* 0-2 1,10,20 * *'

At a first glance, it seems DateTime::Event objects don't do this.


As far as I can see,

 use DateTime::Cron::Simple;
 DateTime::Cron::Simple->new($cron)->validate_time($dt);

is equal to:

 use DateTime::Event::Cron;
 DateTime::Event::Cron->from_cron( cron => $cron )->valid($dt);


--
Tatsuhiko Miyagawa


Re: Template::Stash + DateTime overloading

2006-09-23 Thread Tatsuhiko Miyagawa

Thanks! I forwarded the mail as a patch to template-toolkit mailing list.

On 9/23/06, Daisuke Maki <[EMAIL PROTECTED]> wrote:

Smells like a TT problem.
The line in question at Template::Stash is reads:

   my $atroot  = ($root eq $self);

This logic exists so such that TT knows if it's looking at the implicit
stash context, or a child element in the stash.

The same logic, if I'm not mistaken, in the XS version reads:

   atroot = sv_derived_from(root, TT_STASH_PKG);

So if I change line 685 of Stash.pm to

   my $atroot  = eval { $root->isa(__PACKAGE__) };

Voila!

   [EMAIL PROTECTED] daisuke$ perl test.pl
   # DateTime 0.34
   # Template 2.15
   ok 1 - ok
   ok 2 - ok
   1..2

--d

Tatsuhiko Miyagawa wrote:
> Hi,
>
> Passing DateTime object to TT (Template Toolkit) without Stash::XS
> built, DateTime overloading gives you an annoying error like
> following. (See DATA section for the result on my box.)
>
> Is it something fixable on the user's end, or simply the bug of
> DateTime, or TT?
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> use DateTime;
> use Template;
> use Template::Stash;
> use Template::Stash::XS;
> use Test::More 'no_plan';
>
> diag "DateTime $DateTime::VERSION";
> diag "Template $Template::VERSION";
>
> my $tmpl = < today is [% date.ymd %]
> TMPL
>
> for my $stash ( Template::Stash->new, Template::Stash::XS->new ) {
>my $tt = Template->new({ STASH => $stash });
>ok( $tt->process(\$tmpl, { date => DateTime->now }, \my $out),
> $tt->error || "ok");
> }
>
> __END__
> # DateTime 0.30
> # Template 2.14
> not ok 1 - undef error - Cannot compare a datetime to a regular scalar
> at /usr/local/lib/perl/5.8.4/DateTime.pm line 1435.
> #
> #   Failed test 'undef error - Cannot compare a datetime to a regular
> scalar at /usr/local/lib/perl/5.8.4/DateTime.pm line 1435.
> # '
> #   in /home/miyagawa/tmp/tt-datetime.pl at line 19.
> ok 2 - ok
> 1..2
> # Looks like you failed 1 test of 2.
>
>





--
Tatsuhiko Miyagawa


Template::Stash + DateTime overloading

2006-09-22 Thread Tatsuhiko Miyagawa

Hi,

Passing DateTime object to TT (Template Toolkit) without Stash::XS
built, DateTime overloading gives you an annoying error like
following. (See DATA section for the result on my box.)

Is it something fixable on the user's end, or simply the bug of DateTime, or TT?

#!/usr/bin/perl
use strict;
use warnings;
use DateTime;
use Template;
use Template::Stash;
use Template::Stash::XS;
use Test::More 'no_plan';

diag "DateTime $DateTime::VERSION";
diag "Template $Template::VERSION";

my $tmpl = <new, Template::Stash::XS->new ) {
   my $tt = Template->new({ STASH => $stash });
   ok( $tt->process(\$tmpl, { date => DateTime->now }, \my $out),
$tt->error || "ok");
}

__END__
# DateTime 0.30
# Template 2.14
not ok 1 - undef error - Cannot compare a datetime to a regular scalar
at /usr/local/lib/perl/5.8.4/DateTime.pm line 1435.
#
#   Failed test 'undef error - Cannot compare a datetime to a regular
scalar at /usr/local/lib/perl/5.8.4/DateTime.pm line 1435.
# '
#   in /home/miyagawa/tmp/tt-datetime.pl at line 19.
ok 2 - ok
1..2
# Looks like you failed 1 test of 2.


--
Tatsuhiko Miyagawa


Re: Quick Fix for DateTime::Format::W3CDTF

2006-03-05 Thread Tatsuhiko Miyagawa
It's not "rolled in", but the D::F::Builder just has W3CDTF.pm in
examples/ directory to show how you can reimplement W3CDTF using
Builder framework, at least it looks like.

On 3/5/06, Dave Rolsky <[EMAIL PROTECTED]> wrote:
> On Sat, 4 Mar 2006, kellan wrote:
>
> >
> > On 3/4/06, Tatsuhiko Miyagawa <[EMAIL PROTECTED]> wrote:
> >> 1997-07-16T19:20:30.45+01:00 is a valid W3CDTF format but D::F::W3CDTF
> >> thinks it's invalid. Here's a quick'n nasty patch.
> >
> > On a related note the existence of two D::F::W3CDTF's on CPAN causes a
> > certain amount of confusion.  There is my original module, which has
> > subsquently been rolled into D::F::Builder.
>
> I only see one when I search for it on search.cpan.org or via the cpanplus
> shell. Why would it be rolled in anyway? That wouldn't make much sense.
>
>
> -dave
>
> /*===
> VegGuide.Org    www.BookIRead.com
> Your guide to all that's veg.   My book blog
> ===*/
>


--
Tatsuhiko Miyagawa


Quick Fix for DateTime::Format::W3CDTF

2006-03-04 Thread Tatsuhiko Miyagawa
1997-07-16T19:20:30.45+01:00 is a valid W3CDTF format but D::F::W3CDTF
thinks it's invalid. Here's a quick'n nasty patch.


=== lib/DateTime/Format/W3CDTF.pm
==
--- lib/DateTime/Format/W3CDTF.pm   (revision 25201)
+++ lib/DateTime/Format/W3CDTF.pm   (local)
@@ -66,6 +66,9 @@
 $p{time_zone} = 'floating';
 }

+# strip the decimal fraction digits
+$date =~ s/(\d\d)\.\d+$/$1/;
+
 my $format = $valid_formats{ length $date }
 or die "Invalid W3CDTF datetime string ($original)";



--
Tatsuhiko Miyagawa


How to get Year + Month with Locales

2006-02-06 Thread Tatsuhiko Miyagawa
How can I get "Year + Month" with DateTime::Locale framework?

All I want is a string for a valid year-month, like:

  January, 2006 (en_US)
  2006 年 1 月 (ja_JP)

Neither of available formats like lond_date_format, full_date_format
and medium_date_format suffice my need.

Thanks,

--
Tatsuhiko Miyagawa


Re: [ANNOUNCE] DateTime-Calendar-Japanese 0.01 and DateTime-Format-Japanese 0.01

2003-04-02 Thread Tatsuhiko Miyagawa
At Tue, 01 Apr 2003 17:31:06 -0800,
Daisuke Maki wrote:
> 
> I've hacked together DT::Calendar::Japanese and DT::Format::Japanese. Is
> there anybody on this list that can use Japanese on his machine?

Here, here ;-)

I'd love to look into these modules in this weekend, hopefully.

> Features:
>   DT::Calendar::Japanese:
>  - support for all Japanese eras since 645 A.D, including
>1331 and 1392 where there were two regimes claiming
>their own eras
> 
>   DT::Format::Japanese:
>  - support kanji, zenkaku arabic, and ascii arabic numbers
>  - support eras
> 
> I'm waiting for my PAUSE ID, but meanwhile, they are up here:
> 
>   http://www.wafu.ne.jp/~daisuke/DateTime-Calendar-Japanese-0.01.tar.gz
>   http://www.wafu.ne.jp/~daisuke/DateTime-Format-Japanese-0.01.tar.gz
> 
> Pls let me know if I did anything glaringly wrong.


-- 
Tatsuhiko Miyagawa <[EMAIL PROTECTED]>


patch for DateTime::Calendar::Julian

2003-02-28 Thread Tatsuhiko Miyagawa
Here's a patch to

* pass on 5.005_03. (weird thing going on with not vs. ! in Test:More::ok())
* shut up warnings against "my variables $d ..." 

--
Tatsuhiko Miyagawa <[EMAIL PROTECTED]>


--- t/1.t~  Fri Feb 28 06:55:26 2003
+++ t/1.t   Fri Feb 28 17:21:06 2003
@@ -21,11 +21,11 @@
 [ '/01/03', '/01/01' ], # 1 BC
 ['-4712/01/01','-4713/11/24' ], # Julian Day 1
   ) {
-my ($y, $m, $d) = split '/', $date->[0];
+my ($y, $m, $day) = split '/', $date->[0];
 # time_zone to work around a bug(?) in early DateTime versions
 my $d = DateTime::Calendar::Julian->new(year  => $y,
 month => $m,
-day   => $d,
+day   => $day,
 time_zone => 'floating' );
 my $dt = DateTime->from_object( object => $d );
 is($dt->ymd('/'), $date->[1], "converting $date->[0] to Gregorian");
@@ -35,7 +35,7 @@
 }
 
 $d = DateTime::Calendar::Julian->new(year => 2003);
-ok(not($d->is_leap_year), 'non-leap year');
+ok(!($d->is_leap_year), 'non-leap year');
 
 $d = DateTime::Calendar::Julian->new(year => 2004);
 ok($d->is_leap_year, 'ordinary leap year');


ANNOUNCE: Date::Range::Birth 0.01

2001-12-07 Thread Tatsuhiko Miyagawa

just uploaded Date::Range::Birth onto CPAN, which provides a way
to construct date-range object for birthday of an age.


The URL

http://bulknews.net/lib/archives/Date-Range-Birth-0.01.tar.gz

has entered CPAN as

  file: $CPAN/authors/id/M/MI/MIYAGAWA/Date-Range-Birth-0.01.tar.gz
  size: 2281 bytes
   md5: d65add69c4d8f37b39b27fa7b7fe72e1


NAME
   Date::Range::Birth - range of birthday for an age

SYNOPSIS
 use Date::Range::Birth;

 # birthday for those who are 24 years old now
 my $range = Date::Range::Birth->new(24);

 # birthday for those who are 24 years old in 2001-01-01
 my $date   = Date::Simple->new(2001, 1, 1);
 my $range2 = Date::Range::Birth->new(24, $date);

 # birthday for those who are between 20 and 30 yeard old now
 my $range3 = Date::Range::Birth->new([ 20, 30 ]);


DESCRIPTION
   Date::Range::Birth is a subclass of Date::Range, which
   provides a way to construct range of dates for birthday.

METHODS
   new

 $range = Date::Range::Birth->new($age);
 $range = Date::Range::Birth->new($age, $date);
 $range = Date::Range::Birth->new([ $young, $old ]);
 $range = Date::Range::Birth->new([ $young, $old ], $date);

   returns Date::Range::Birth object for birthday of the
   age. If $date (Date::Simple object) provided, returns
   range of birthday for those who are $age years old in
   $date. Default is today (now).

   If the age is provided as array reference (like [
   $young, $old ]), returns range of birthday for those
   who are between $young - $old years old.

   Other methods are inherited from Date::Range. See the
   Date::Range manpage for details.

AUTHOR
   Original idea by ikechin <[EMAIL PROTECTED]>

   Code implemented by Tatsuhiko Miyagawa
   <[EMAIL PROTECTED]>

   This library is free software; you can redistribute it
   and/or modify it under the same terms as Perl itself.

SEE ALSO
   the Date::Range manpage, the Date::Simple manpage, the
   Date::Calc manpage




--
Tatsuhiko Miyagawa <[EMAIL PROTECTED]>




ANNOUNCE: Date::Japanese::Era 0.01

2001-08-31 Thread Tatsuhiko Miyagawa
Annoucing the Date-related module which handles conversion between
Japanese Era and Gregorian calendar. 

--

The URL

http://bulknews.net/lib/archives/Date-Japanese-Era-0.01.tar.gz

has entered CPAN as

  file: $CPAN/authors/id/M/MI/MIYAGAWA/Date-Japanese-Era-0.01.tar.gz
  size: 4196 bytes
   md5: 7050ba6ec2a0ac0027d8dc9d6812a4e1


NAME
Date::Japanese::Era - Conversion between Japanese Era / Gregorian
calendar

SYNOPSIS
  use Date::Japanese::Era;

  # from Gregorian (month + day required)
  $era = Date::Japanese::Era->new(1970, 1, 1);

  # from Japanese Era
  $era = Date::Japanese::Era->new('$B>name; # '$B>gengou;   # same

  $year  = $era->year; # 52
  $gregorian = $era->gregorian_year;   # 1977

DESCRIPTION
Date::Japanese::Era handles conversion between Japanese Era and
Gregorian calendar.

METHODS
codeset
  $codeset = Date::Japanese::Era->codeset;
  Date::Japanese::Era->codeset($encoding);

sets / gets external encoding of Japanese era names. For example
with the following code, input and output of era names are encoded
in UTF-8.

  Date::Japanese::Era->codeset('utf8');
  $era = Date::Japanese::Era->new($name, $year); # $name is UTF-8
  print $era->name;  # also UTF-8

You need Jcode module installed to make use of this feature.
Otherwise, calls to codeset() are simply ignored (with warning).

new
  $era = Date::Japanese::Era->new($year, $month, $day);
  $era = Date::Japanese::Era->new($era_name, $year);

Constructs new Date::Japanese::Era instance. When constructed from
Gregorian date, month and day is required. You need Date::Calc to
construct from Gregorian.

Name of era can be either of Japanese / ASCII. Input encodings can
be specified via codeset(), suppose you have Jcode module installed.
Default is EUC-JP.

Exceptions are thrown when inputs are invalid (e.g: non-existent era
name and year combination, unknwon era-name, etc.).

name
  $name = $era->name;

returns era name in Japanese. Encoding can be specified via
codeset() class method. Default is EUC-JP.

gengou
alias for name().

name_ascii
  $name_ascii = $era->name_ascii;

returns era name in US-ASCII.

year
  $year = $era->year;

returns year as Japanese era.

gregorian_year
  $year = $era->gregorian_year;

returns year as Gregorian.

EXAMPLES
  # 2001 is H-13
  my $era = Date::Japanese::Era->new(2001, 8, 31);
  printf "%s-%s", uc(substr($era->name_ascii, 0, 1)), $era->year;

  # to Gregorian
  my $era = Date::Japanese::Era->new('$BJ?@.(B', 13);
  print $era->gregorian_year;   # 2001

CAVEATS
*   Days when era just changed are handled as newer (later) one.

*   Currently supported era is up to 'meiji'.

*   If someday current era (heisei) is changed,
Date::Japanese::Era::Table should be upgraded. (Table is declared as
global variable, so you can overwrite it if necessary).

TODO
*   Date parameters can be in various format. I should replace
Date::Simple or whatever for that.

*   Support earlier eras.

AUTHOR
Tatsuhiko Miyagawa <[EMAIL PROTECTED]>

This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

SEE ALSO
the Date::Calc manpage, the Jcode manpage, the Date::Simple manpage



--
Tatsuhiko Miyagawa <[EMAIL PROTECTED]>


countdown to U1e9

2001-08-31 Thread Tatsuhiko Miyagawa

Just a FYI. 10 digit time_t will come in just a week.

http://search.cpan.org/search?dist=Dunce-time

NAME
Dunce::time - Protects against sloppy use of time.

SYNOPSIS
  use Dunce::time;

  my $this = time;
  my $that = time;

  my @sorted = sort $this, $that; # die with an error
  my @numerically_sorted = sort { $a <=> $b } $this, $that; # OK

DESCRIPTION
On Sun Sep 9 01:46:40 2001 GMT, time_t (UNIX epoch) reaches 10 digits.
Sorting time()'s as strings will cause unexpected result after that.

When Dunce::time is used, it provides special version of time() which
will die with a message when compared as strings.

USAGE
Just use the module. If it detects a problem, it will cause your program
to abort with an error. If you don't like this behaviour, you can use
the module with tags like ":WARN" or ":FIX".

  use Dunce::time qw(:WARN);

With ":WARN" tag, it will just warn instead of dying.

  use Dunce::time qw(:FIX);
  @sorted = sort @time; # acts like sort { $a <=> $b } @time;

With ":FIX" tag, it will warn and change the comparison behaviour so
that it acts like compared numerically.

CAVEATS
You store the variables into storage (like DBMs, databases), retrieve
them from storage, and compare them as strings ... this can't detect in
such a case.

AUTHOR
Tatsuhiko Miyagawa <[EMAIL PROTECTED]>

This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

SEE ALSO
the Dunce::time::Zerofill manpage, the D::oh::Year manpage, the overload
manpage, the perl manpage

--
Tatsuhiko Miyagawa <[EMAIL PROTECTED]>