Re: problem case with recurrence in DateTime::Event::ICal

2005-10-05 Thread Mark D. Anderson

On Wed, 5 Oct 2005 10:34:45 -0300, "Flavio S. Glock" <[EMAIL PROTECTED]>
said:

> DateTime::Set 0.25
> - t/15time_zone.t does it's own time zone "add_duration" handling

Yippee! This seems to have done it.

-mda


Re: problem case with recurrence in DateTime::Event::ICal

2005-10-04 Thread Mark D. Anderson
Maybe I need something else updated, or maybe I need to
not be living in california :), but for me, 
DateTime-Set-0.24 is refusing to install due to failing
a time zone test:

> install DateTime::Set

...
_callback_previous: Delta components are: months 0 days 0 minutes 0
seconds 0 nanoseconds 0
_callback_previous: iterator can't find a previous value, got 2001-12-31
after 2001-12-31 at
/root/.cpan/build/DateTime-Set-0.24/blib/lib/DateTime/Set.pm line 338.
t/15time_zoneNOK 14
# Failed test (t/15time_zone.t at line 124)
#  got: 'Mon'
# expected: 'Sun'
# Looks like you failed 5 tests of 14.
t/15time_zonedubious

-mda


On Tue, 4 Oct 2005 15:26:50 -0300, "Flavio S. Glock" <[EMAIL PROTECTED]>
said:
> 2005/10/3, Mark D. Anderson <[EMAIL PROTECTED]>:
> > Your fix now makes the test program work as it was written...
> >
> > However, it still fails if DTEND or UNTIL is specified.
> 
> Sorry - fixed in DateTime::Set 0.24
> (this should have been fixed in 0.23, but it was rolled back by mistake)
> 
> - Flavio S. Glock


Re: problem case with recurrence in DateTime::Event::ICal

2005-10-03 Thread Mark D. Anderson
Your fix now makes the test program work as it was written...

However, it still fails if DTEND or UNTIL is specified.

I have updated the test program at the url to reflect this problem:

http://discerning.com/hacks/bugs/dtbug.pl

Thanks for your efforts so far

-mda

On Mon, 3 Oct 2005 11:52:28 -0300, "Flavio S. Glock" <[EMAIL PROTECTED]>
said:
> Thank you for the test - that bug should be fixed now.
> Please upgrade DateTime-Set to version 0.23
> 
> - Flavio S. Glock
> 
> 2005/9/30, Mark D. Anderson <[EMAIL PROTECTED]>:
> >
> > >
> > > I was not able to replicate the error message - would you send me a
> > > small runnable program?
> >
> > You can find one at
> > http://discerning.com/hacks/bugs/dtbug.pl
> >


Re: problem case with recurrence in DateTime::Event::ICal

2005-09-30 Thread Mark D. Anderson

On Fri, 30 Sep 2005 14:07:55 -0300, "Flavio S. Glock" <[EMAIL PROTECTED]>
said:
> DateTime-Event-ICal-0.09 was uploaded to CPAN - it fixes the warnings
> while calculating BYSETPOS.
> 
> Mark D. Anderson wrote:
> > Could you try again without the "dtend" and "until" args?
> > Combining with bysetpos and dtstart being set still gives me problems.
> 
> I was not able to replicate the error message - would you send me a
> small runnable program?

You can find one at 
http://discerning.com/hacks/bugs/dtbug.pl

It is still failing for me, after the latest changes.

> 
> > btw, the RRULE processing seems rather inefficient.
> 
> BYSETPOS calculates the whole set, and then discards the uninteresting
> items. The code is in DateTime/Event/ICal.pm line 361.
> BYSETPOS=1 could be special-cased to calculate only the first instance
> (patches are welcome).

I will be immensely more motivated to take a crack at
working on optimization once i get this to work at all :)

-mda



Re: problem case with recurrence in DateTime::Event::ICal

2005-09-23 Thread Mark D. Anderson
Sorry I lied, upgrading my modules from cpan didn't help at all;
it is just that some debug statements I put in to decipher the
problem actually papered it over.

In particular, 

1. in DateTime::Event::ICal

previous =>
sub {
 ...
my @list = $subset->as_list;
print STDERR (__PACKAGE__, " ERROR: empty list\n") and
return undef unless @list;

2. in Set::Infinite::_recurrence function _recurrence

$min2 = $callback_previous->( $min1 );
print STDERR __PACKAGE__, " ERROR: no min2 from
$callback_previous\n" and return $set->new() unless
$min2;

So with those two insertions which also return early, the code
works ok with my RRULE statements.
Those error statements *do* get printed.
So I've got a workaround, but not one I understand; i just found these
points by
printing stack traces from the undefined symbol warnings.

-mda


Re: problem case with recurrence in DateTime::Event::ICal

2005-09-23 Thread Mark D. Anderson
> Both examples work here - maybe you need to update DateTime.pm?
> - Flavio S. Glock

I upgraded everything from cpan, and I'm closer.
Could you try again without the "dtend" and "until" args?
Combining with bysetpos and dtstart being set still gives me problems.

[btw, is there some easy way to get cpan to upgrade 
everything under some package like DateTime::* ?
i had to write a small perl program just to upgrade
my perl, which seems like the kind of thing a perl-hater
would use as evidence against us...]

btw, the RRULE processing seems rather inefficient.
For example, to process:

   RRULE:FREQ=MONTHLY;INTERVAL=1;BYDAY=TH;BYSETPOS=1;UNTIL=20061229

I counted over 1000 calls to DateTime::_compare_overload
I tried delving into the recurrence source code, but had to
retreat in order to preserve my sanity :(.  To much recursion,
anonymous subs, and random inline constants like "10"

-mda

On Fri, 23 Sep 2005 00:32:18 -0700, "Mark D. Anderson"
<[EMAIL PROTECTED]> said:
> Using DateTime::Event::ICal $VERSION = 0.08;
> 
> this test case causes a lot of warnings (and eventual death,
> if called from DateTime::Format::ICal).
> 
> it happens when both bysetpos and dtstart are set.
> 
> I ran into this using an ics file "in the wild";
> this isn't some artifical case.
> 
> -mda
> 
> 
> use DateTime::Event::ICal;
> use DateTime;
> 
> DateTime::Event::ICal->recur(
>freq => 'monthly',
>interval => '09',
>byday => ['th'],
>bysetpos => [1],
>bymonthday => [15],
>count => '2',
>dtstart => DateTime->now(),
>  dtend => DateTime->new(year => '2007'),
>  until => DateTime->new(year => '2007'),
>);
> 
> or alternatively:
> 
> DateTime::Format::ICal->parse_recurrence(
>  recurrence =>
>  
> 'FREQ=MONTHLY;INTERVAL=09;BYDAY=TH;BYSETPOS=1;BYMONTHDAY=15;COUNT=2',
>dtstart => DateTime->now(),
>  dtend => DateTime->new(year => '2007'),
>  until => DateTime->new(year => '2007'),
>  ) 
> 
> 
> ---
> Use of uninitialized value in sort at
> /usr/local/lib/perl5/site_perl/5.8.4/DateTime/Event/ICal.pm line 469.
> Use of uninitialized value in negation (-) at
> /usr/local/lib/perl5/site_perl/5.8.4/i686-linux/DateTime.pm line 1246.
> Use of uninitialized value in sort at
> /usr/local/lib/perl5/site_perl/5.8.4/DateTime/Event/ICal.pm line 469.
> Use of uninitialized value in negation (-) at
> /usr/local/lib/perl5/site_perl/5.8.4/i686-linux/DateTime.pm line 1246.
> ...
> 
> Parameter #1 ("0") to DateTime::add_duration was not a
> 'DateTime::Duration' (it is a 0)
>  at /usr/local/lib/perl5/site_perl/5.8.4/Set/Infinite/_recurrence.pm
>  line 157


problem case with recurrence in DateTime::Event::ICal

2005-09-23 Thread Mark D. Anderson
Using DateTime::Event::ICal $VERSION = 0.08;

this test case causes a lot of warnings (and eventual death,
if called from DateTime::Format::ICal).

it happens when both bysetpos and dtstart are set.

I ran into this using an ics file "in the wild";
this isn't some artifical case.

-mda


use DateTime::Event::ICal;
use DateTime;

DateTime::Event::ICal->recur(
   freq => 'monthly',
   interval => '09',
   byday => ['th'],
   bysetpos => [1],
   bymonthday => [15],
   count => '2',
   dtstart => DateTime->now(),
 dtend => DateTime->new(year => '2007'),
 until => DateTime->new(year => '2007'),
   );

or alternatively:

DateTime::Format::ICal->parse_recurrence(
 recurrence =>
 
'FREQ=MONTHLY;INTERVAL=09;BYDAY=TH;BYSETPOS=1;BYMONTHDAY=15;COUNT=2',
   dtstart => DateTime->now(),
 dtend => DateTime->new(year => '2007'),
 until => DateTime->new(year => '2007'),
 ) 


---
Use of uninitialized value in sort at
/usr/local/lib/perl5/site_perl/5.8.4/DateTime/Event/ICal.pm line 469.
Use of uninitialized value in negation (-) at
/usr/local/lib/perl5/site_perl/5.8.4/i686-linux/DateTime.pm line 1246.
Use of uninitialized value in sort at
/usr/local/lib/perl5/site_perl/5.8.4/DateTime/Event/ICal.pm line 469.
Use of uninitialized value in negation (-) at
/usr/local/lib/perl5/site_perl/5.8.4/i686-linux/DateTime.pm line 1246.
...

Parameter #1 ("0") to DateTime::add_duration was not a
'DateTime::Duration' (it is a 0)
 at /usr/local/lib/perl5/site_perl/5.8.4/Set/Infinite/_recurrence.pm
 line 157


Re: support for precision?

2004-09-16 Thread Mark D. Anderson

> Have a look at DateTime::Incomplete.

it doesn't parse.
as you identify, the key question is how to get the format
modules to use it instead.

> Of course, DateTime::Format::ISO8601 still sets a default if you use it
> to 
> parse the datetime. (Joshua: You accept a DateTime object for filling in 
> missing parts; is there any chance you could also accept a 
> DateTime::Incomplete object? If such an object is supplied, your parser
> would 
> return a DT:I object)

Initial experiments suggest not:

my $basedt = DateTime::Incomplete->new(time_zone => 'floating');
my $iso8601 = DateTime::Format::ISO8601->new(base_datetime => $basedt);
my $dt = $iso8601->parse_datetime('2004');
print "has_year=", $dt->has_year(), "\n";

Use of uninitialized value in subroutine entry at
/usr/local/lib/perl5/site_perl/5.8.4/i686-linux/DateTime.pm line 393.
Use of uninitialized value in subroutine entry at
/usr/local/lib/perl5/site_perl/5.8.4/i686-linux/DateTime.pm line 394.
Can't locate object method "has_year" via package "DateTime" at test.pl
line 21.

Looking at the source code to ISO8601, it appears it has hardcoded
'DateTime' for the constructor class everywhere.

Ideally I would think this would be something to do at the Builder
level, so that more than just ISO8601 would benefit.

Or, just make the core DateTime.pm module support this feature,
obviating the need for DateTime::Incomplete

-mda


Re: more convenient localized name lookups

2004-09-16 Thread Mark D. Anderson

> 2. Otherwise you can use a DateTime::Locale object:
> 
> use DateTime::Locale;
> my $en = DateTime::Locale->load('en')
> print $en->month_abbreviations->[ $month_number - 1 ];

This works great; thanks.

-mda


more convenient localized name lookups

2004-09-15 Thread Mark D. Anderson
Am I correct that the only way to map the number 12 to "Dec"
is this mouthful:

# DateTime constructor produces an error if only month is supplied.
substr(new DateTime(year => 2004, month => 12)->month_name(), 0, 3);

-mda




Re: support for precision?

2004-09-15 Thread Mark D. Anderson

On Thu, 16 Sep 2004 14:41:21 +0900, "Daisuke Maki" <[EMAIL PROTECTED]>
said:
> 
> That's the right behavior because DateTime represents a point in time. 
> "2004" represents 1 year, a span of time.
> 
> What exactly do you want to do?

I have a database table with a column containing iso 8601 date strings.
Not all of these values have the same precision: some are accurate only
to the year, some to the day, and some to the hour and minute.

I want to know what precision it was so that I can display these
datetimes to the user -- not in the original format but in some
other desirable format suitable for that level of precision.

But I can't, using DateTime::*, because it loses all information
about the original precision.

This isn't impossible; i've got my own regexp parser of ISO8601
that retains an internal precision value.
I was hoping to use DateTime because it supports more of ISO8601
than I do. But it doesn't seem to have this feature.

-mda


support for precision?

2004-09-15 Thread Mark D. Anderson
There seems to be no support for keeping track of precision?

In particular, suppose my original string is "2004".
I would like to later print that out as "2004", *not* as
"2004-01-01", because somehow the DateTime object kept
track of the level of precision.

But in this code:
  my $dt = DateTime->new(year => 2004);
  print "year=", $dt->year, " month=", $dt->month, "\n";

the output is:
 year=2004 month=1

I can't specify an illegal value like -1.
And there is no way to turn off the builtin defaulting.

-mda





more convenient time zone support

2004-09-15 Thread Mark D. Anderson
I have an iso8601 time string to parse in $str, and
a default timezone id in $tzid, which is to be used
if $str has no timezone.

I want to get an epoch.

here is my implementation:

sub iso_to_epoch {
my ($str, $defaulttz) = @_;
my $dt = DateTime::Format::ISO8601->parse_datetime( $str );
$dt->set_time_zone($defaulttz) if $dt->time_zone_long_name() eq
'floating' && $defaulttz;
return $dt->epoch();
}

The above does work.
However, it isn't particular clean, requiring 3 calls.

I suppose I could specify the default timezone first:

sub iso_to_epoch {
   my ($str, $defaulttz) = @_;
   my $basedt = DateTime->new(time_zone => $defaulttz);
   my $iso8601 = DateTime::Format::ISO8601->new(base_datetime =>
   $basedt);
   my $dt = $iso8601->parse_datetime($str);
   return $dt->epoch();
}

but that is about as many lines.

Here are some hypothetical ways this might be shortened:

return DateTime::Format::ISO8601->parse(str => $str, default_time_zone
=> $defaulttz)->epoch()

return DateTime->parse(format => 'ISO8601', str => $str, base_datetime
=> {time_zone => $defaulttz})->epoch()


-mda