Re: issues with Data::ICal::DateTime and possible DateTime::Set

2017-08-21 Thread Flavio S. Glock
Data::ICal::DateTime 0.82 implements the fix discussed below.

0.82 - Mon 21 Aug 2017
* Set recurrence timezone to the same as the 'start' attribute (fix
github issue #2)


2017-08-18 21:10 GMT+02:00 Flavio S. Glock <fgl...@gmail.com>:

> This patch fixes the problem - but as I explained in the previous mail,
> I'm not sure if it is the right thing to do (the alternative is that
> DateTime::Event::ICal didn't ignore the time_zone in dtstart).
>
> diff --git a/lib/Data/ICal/DateTime.pm b/lib/Data/ICal/DateTime.pm
> index ecf9e2f..ab49e78 100644
> --- a/lib/Data/ICal/DateTime.pm
> +++ b/lib/Data/ICal/DateTime.pm
> @@ -499,6 +499,7 @@ sub _rule_set {
>  for (@{ $self->property($name) }) {
>  my $recur   = DateTime::Format::ICal->parse_recurrence(recurrence
> => $_->value, dtstart => $start);
>  # $recur->set_time_zone($_->parameters->{TZID}) if
> $_->parameters->{TZID};
> +$recur->set_time_zone($start->time_zone) if
> !$start->time_zone->is_floating;
>  $set = $set->union($recur);
>  }
>  # $set->set_time_zone($tz);
>
>
> 2017-08-18 19:27 GMT+02:00 Flavio S. Glock <fgl...@gmail.com>:
>
>> (forwarding to DateTime list because this looks interesting)
>>
>> I've created this test - https://gist.github.com/fglock
>> /cf1117ad000b41d9e5dbee6fa8b78993
>>
>> this fails (set time zone implicitly through dtstart):
>>
>> $a = DateTime::Event::ICal->recur(
>> dtstart => $dt19970902T09_tz ,
>> freq => 'daily',
>> count => 10 )
>> ->intersection( $period_1995_1999 );
>>
>> this other test works (time zone is set explicitly for the whole
>> recurrence):
>>
>> $a = DateTime::Event::ICal->recur(
>> dtstart => $dt19970902T09_tz ,
>> freq => 'daily',
>> count => 10 )
>> ->set_time_zone( "America/New_York" )
>> ->intersection( $period_1995_1999 );
>>
>> I believe this is the correct behaviour (though it should warn!), because
>> http://www.ietf.org/rfc/rfc2445.txt
>> says:
>>
>> 
>>
>> Dawson & Stenerson  Standards Track   [Page 117]
>> 
>> RFC 2445   iCalendar   November 1998
>>
>>
>>The "DTSTART" and "DTEND" property pair or "DTSTART" and "DURATION"
>>property pair, specified within the iCalendar object defines the
>>first instance of the recurrence. When used with a recurrence rule,
>>the "DTSTART" and "DTEND" properties MUST be specified in local time
>>and the appropriate set of "VTIMEZONE" calendar components MUST be
>>included. For detail on the usage of the "VTIMEZONE" calendar
>>component, see the "VTIMEZONE" calendar component definition.
>>
>> I *think* DateTime::Event::ICal is doing the right thing, but the module 
>> documentation is not clear:
>>
>> 
>>
>> This method takes parameters which correspond to the rule parts
>> specified in section 4.3.10 of RFC 2445.  Rather than rewrite that RFC
>> here, you are encouraged to read that first if you want to understand
>> what all these parameters represent.
>>
>> 
>>
>> It *could* as well also use the time_zone from "dtstart".
>>
>> Simon: do you think this explains the problem, and can this can be fixed in 
>> your module maybe?
>>
>> Flávio S. Glock
>>
>>
>>
>> 2017-08-18 18:28 GMT+02:00 Flavio S. Glock <fgl...@gmail.com>:
>>
>>> just to confirm, I did a fresh install and I get:
>>>
>>> t/01.parse_recurring.t .. 1/18
>>> #   Failed test at t/01.parse_recurring.t line 25.
>>> #  got: 'floating'
>>> # expected: 'Europe/London'
>>>
>>> I'm investigating a bit
>>>
>>> Flávio
>>>
>>>
>>> 2017-08-18 17:33 GMT+02:00 Th.J. van Hoesel <slrn406268...@gmail.com>:
>>> > just fiddling along, it works if I first install
>>> FGLOCK/DateTime-Event-Recurrence-0.16
>>> >
>>> >> On 18 Aug 2017, at 15:34, Th.J. van Hoesel <th.j.v.hoe...@me.com>
>>> wrote:
>>> >>
>>> >> Hi Flávio, Hello Simon,
>>> >>
>>> >> i've some issues with installing Data::Ical::DateTime and I can not
>>> exactly say who is in the right or who is in the wrong, that would require
>>> more investigation.
>>> >>
>>> >> Data::Ical::DateTime is depending on DateTime::Event::Recurrence,
>>> with is dependent on DateTime::Set. When that was changed back in november
>>> 2015, that is when Data::ICal::DateTime started failing on CPAN testers.
>>> >>
>>> >> Maybe one does a wrong call and should actually had expected to get
>>> "floating" timezones, maybe one does expected that his timezone from the
>>> .ics test file would be honoured.
>>> >>
>>> >> Could you please be so kind and have a look, you probably do
>>> understand the problem-space much better than I do. Would I have
>>> understood, I probably would had sent a bug fix
>>> >>
>>> >> Theo
>>> >>
>>> >> PS. It is part of the "Act-out-of-the-Box" install script, and it
>>> just looks ugly to do a force install, but it will do the job for now
>>> >
>>>
>>
>>
>>
>


Re: issues with Data::ICal::DateTime and possible DateTime::Set

2017-08-18 Thread Flavio S. Glock
This patch fixes the problem - but as I explained in the previous mail, I'm
not sure if it is the right thing to do (the alternative is that
DateTime::Event::ICal didn't ignore the time_zone in dtstart).

diff --git a/lib/Data/ICal/DateTime.pm b/lib/Data/ICal/DateTime.pm
index ecf9e2f..ab49e78 100644
--- a/lib/Data/ICal/DateTime.pm
+++ b/lib/Data/ICal/DateTime.pm
@@ -499,6 +499,7 @@ sub _rule_set {
 for (@{ $self->property($name) }) {
 my $recur   = DateTime::Format::ICal->parse_recurrence(recurrence
=> $_->value, dtstart => $start);
 # $recur->set_time_zone($_->parameters->{TZID}) if
$_->parameters->{TZID};
+$recur->set_time_zone($start->time_zone) if
!$start->time_zone->is_floating;
 $set = $set->union($recur);
 }
 # $set->set_time_zone($tz);


2017-08-18 19:27 GMT+02:00 Flavio S. Glock <fgl...@gmail.com>:

> (forwarding to DateTime list because this looks interesting)
>
> I've created this test - https://gist.github.com/fglock
> /cf1117ad000b41d9e5dbee6fa8b78993
>
> this fails (set time zone implicitly through dtstart):
>
> $a = DateTime::Event::ICal->recur(
> dtstart => $dt19970902T09_tz ,
> freq => 'daily',
> count => 10 )
> ->intersection( $period_1995_1999 );
>
> this other test works (time zone is set explicitly for the whole
> recurrence):
>
> $a = DateTime::Event::ICal->recur(
> dtstart => $dt19970902T09_tz ,
> freq => 'daily',
> count => 10 )
> ->set_time_zone( "America/New_York" )
> ->intersection( $period_1995_1999 );
>
> I believe this is the correct behaviour (though it should warn!), because
> http://www.ietf.org/rfc/rfc2445.txt
> says:
>
> 
>
> Dawson & Stenerson  Standards Track   [Page 117]
> 
> RFC 2445   iCalendar   November 1998
>
>
>The "DTSTART" and "DTEND" property pair or "DTSTART" and "DURATION"
>property pair, specified within the iCalendar object defines the
>first instance of the recurrence. When used with a recurrence rule,
>the "DTSTART" and "DTEND" properties MUST be specified in local time
>and the appropriate set of "VTIMEZONE" calendar components MUST be
>included. For detail on the usage of the "VTIMEZONE" calendar
>component, see the "VTIMEZONE" calendar component definition.
>
> I *think* DateTime::Event::ICal is doing the right thing, but the module 
> documentation is not clear:
>
> 
>
> This method takes parameters which correspond to the rule parts
> specified in section 4.3.10 of RFC 2445.  Rather than rewrite that RFC
> here, you are encouraged to read that first if you want to understand
> what all these parameters represent.
>
> 
>
> It *could* as well also use the time_zone from "dtstart".
>
> Simon: do you think this explains the problem, and can this can be fixed in 
> your module maybe?
>
> Flávio S. Glock
>
>
>
> 2017-08-18 18:28 GMT+02:00 Flavio S. Glock <fgl...@gmail.com>:
>
>> just to confirm, I did a fresh install and I get:
>>
>> t/01.parse_recurring.t .. 1/18
>> #   Failed test at t/01.parse_recurring.t line 25.
>> #  got: 'floating'
>> # expected: 'Europe/London'
>>
>> I'm investigating a bit
>>
>> Flávio
>>
>>
>> 2017-08-18 17:33 GMT+02:00 Th.J. van Hoesel <slrn406268...@gmail.com>:
>> > just fiddling along, it works if I first install
>> FGLOCK/DateTime-Event-Recurrence-0.16
>> >
>> >> On 18 Aug 2017, at 15:34, Th.J. van Hoesel <th.j.v.hoe...@me.com>
>> wrote:
>> >>
>> >> Hi Flávio, Hello Simon,
>> >>
>> >> i've some issues with installing Data::Ical::DateTime and I can not
>> exactly say who is in the right or who is in the wrong, that would require
>> more investigation.
>> >>
>> >> Data::Ical::DateTime is depending on DateTime::Event::Recurrence, with
>> is dependent on DateTime::Set. When that was changed back in november 2015,
>> that is when Data::ICal::DateTime started failing on CPAN testers.
>> >>
>> >> Maybe one does a wrong call and should actually had expected to get
>> "floating" timezones, maybe one does expected that his timezone from the
>> .ics test file would be honoured.
>> >>
>> >> Could you please be so kind and have a look, you probably do
>> understand the problem-space much better than I do. Would I have
>> understood, I probably would had sent a bug fix
>> >>
>> >> Theo
>> >>
>> >> PS. It is part of the "Act-out-of-the-Box" install script, and it just
>> looks ugly to do a force install, but it will do the job for now
>> >
>>
>
>
>


Fwd: issues with Data::ICal::DateTime and possible DateTime::Set

2017-08-18 Thread Flavio S. Glock
(forwarding to DateTime list because this looks interesting)

I've created this test - https://gist.github.com/fglock/
cf1117ad000b41d9e5dbee6fa8b78993

this fails (set time zone implicitly through dtstart):

$a = DateTime::Event::ICal->recur(
dtstart => $dt19970902T09_tz ,
freq => 'daily',
count => 10 )
->intersection( $period_1995_1999 );

this other test works (time zone is set explicitly for the whole
recurrence):

$a = DateTime::Event::ICal->recur(
dtstart => $dt19970902T09_tz ,
freq => 'daily',
count => 10 )
->set_time_zone( "America/New_York" )
->intersection( $period_1995_1999 );

I believe this is the correct behaviour (though it should warn!), because
http://www.ietf.org/rfc/rfc2445.txt
says:



Dawson & Stenerson  Standards Track   [Page 117]

RFC 2445   iCalendar   November 1998


   The "DTSTART" and "DTEND" property pair or "DTSTART" and "DURATION"
   property pair, specified within the iCalendar object defines the
   first instance of the recurrence. When used with a recurrence rule,
   the "DTSTART" and "DTEND" properties MUST be specified in local time
   and the appropriate set of "VTIMEZONE" calendar components MUST be
   included. For detail on the usage of the "VTIMEZONE" calendar
   component, see the "VTIMEZONE" calendar component definition.

I *think* DateTime::Event::ICal is doing the right thing, but the
module documentation is not clear:



This method takes parameters which correspond to the rule parts
specified in section 4.3.10 of RFC 2445.  Rather than rewrite that RFC
here, you are encouraged to read that first if you want to understand
what all these parameters represent.



It *could* as well also use the time_zone from "dtstart".

Simon: do you think this explains the problem, and can this can be
fixed in your module maybe?

Flávio S. Glock



2017-08-18 18:28 GMT+02:00 Flavio S. Glock <fgl...@gmail.com>:

> just to confirm, I did a fresh install and I get:
>
> t/01.parse_recurring.t .. 1/18
> #   Failed test at t/01.parse_recurring.t line 25.
> #  got: 'floating'
> # expected: 'Europe/London'
>
> I'm investigating a bit
>
> Flávio
>
>
> 2017-08-18 17:33 GMT+02:00 Th.J. van Hoesel <slrn406268...@gmail.com>:
> > just fiddling along, it works if I first install
> FGLOCK/DateTime-Event-Recurrence-0.16
> >
> >> On 18 Aug 2017, at 15:34, Th.J. van Hoesel <th.j.v.hoe...@me.com>
> wrote:
> >>
> >> Hi Flávio, Hello Simon,
> >>
> >> i've some issues with installing Data::Ical::DateTime and I can not
> exactly say who is in the right or who is in the wrong, that would require
> more investigation.
> >>
> >> Data::Ical::DateTime is depending on DateTime::Event::Recurrence, with
> is dependent on DateTime::Set. When that was changed back in november 2015,
> that is when Data::ICal::DateTime started failing on CPAN testers.
> >>
> >> Maybe one does a wrong call and should actually had expected to get
> "floating" timezones, maybe one does expected that his timezone from the
> .ics test file would be honoured.
> >>
> >> Could you please be so kind and have a look, you probably do understand
> the problem-space much better than I do. Would I have understood, I
> probably would had sent a bug fix
> >>
> >> Theo
> >>
> >> PS. It is part of the "Act-out-of-the-Box" install script, and it just
> looks ugly to do a force install, but it will do the job for now
> >
>


small DateTime optimization

2017-03-15 Thread Flavio S. Glock
We've been using this patch at work for years, and I just forgot to
contribute it back. I hope you find it worth applying.

I believe the typical use case was:

  my $dt = $param || DateTime->now();

In this case $param is used in boolean context, which makes a fallback call
to _stringify(). With the patch, "boolean" just returns true.

The stringification change is a micro-optimization, it is not that
important.



# optimize boolean and string
use overload
'""'  => sub {
   $_[0]->ymd('-') . 'T' . $_[0]->hms(':')
 },
bool  => sub { 1 },

'<=>' => '_compare_overload',
'cmp' => '_compare_overload',
'-'   => '_subtract_overload',
'+'   => '_add_overload',
fallback   => 1;


Re: Recurring set does not correctly calculate dates for second Friday of the month.

2017-03-07 Thread Flavio S. Glock
DateTime-Event-Recurrence-0.19 is in CPAN, with
documentation patches related to the "week_start_day" parameter:

-- "week_start_day" parameter no longer marked "for internal use".
-- Fix "week day" examples. Pointed out by Eric Jensen and Zefram
   in a thread started by Andrew Martin in datetime@perl.org
-- Clarify that week_start_day defaults to "1mo", except for
   yearly recurrences that default to "mo". Patches by David Steinbrunner.
-- Updated contact email.


2017-03-02 5:00 GMT+01:00 Zefram :

> Andrew Martin wrote:
> >however 17-02-2017 is the Third Friday, the expected result is 10-02-2017
>
> DateTime::Event::Recurrence->monthly doesn't really do "the Nth Fooday
> of each month".  It gives you either "the Fooday of the Nth week that
> is mostly contained in each month" or "the Fooday of the Nth week that
> started in each month".  Its idea of a week always starts on a specified
> day of the week; the first week that is mostly contained in a month may
> start on any day from three days before the 1st of the month up to the
> 4th of the month.
>
> You *can* use this to get the Nth Fooday of each month, by manipulating
> how the weeks are delimited.  Observe that each week is mostly contained
> in the month that contains its fourth day.  If you're only interested
> in which month contains a specific day of the week, you just have to
> arrange for that day to be the fourth of the week.  So to get the Nth
> Friday of each month, you need to tell it that the week starts on Tuesday:
>
> my $set = DateTime::Event::Recurrence->monthly(weeks => 2,
> days => "fr", week_start_day => "tu");
>
> Or you can use weeks starting in the month, and tell it that the day
> you're interested in is the first day of the week:
>
> my $set = DateTime::Event::Recurrence->monthly(weeks => 2,
> days => "fr", week_start_day => "1fr");
>
> The example in the module's documentation labelled "second tuesday of
> every month" is incorrect.  It actually yields Tuesdays ranging from the
> 9th to the 15th of each month, because it is computing the Tuesdays of
> the second week to start in each month, with the week starting on Monday.
>
> -zefram
>


Re: Recurring set does not correctly calculate dates for second Friday of the month.

2017-03-01 Thread Flavio S. Glock
please check the week_start_day parameter, I believe it will fix
this problem:

http://search.cpan.org/~fglock/DateTime-Event-Recurrence-0.18/lib/DateTime/Event/Recurrence.pm#The_%22week_start_day%22_Parameter

Em terça-feira, 28 de fevereiro de 2017, Andrew Martin 
escreveu:

> Hi,
>
> The following code produces (for me) this output.. ( dd-mm-)
>
> 13-01-2017 Test event
> 17-02-2017 Test event
> 17-03-2017 Test event
> 14-04-2017 Test event
> 12-05-2017 Test event
> 16-06-2017 Test event
> 14-07-2017 Test event
> 18-08-2017 Test event
> 15-09-2017 Test event
> 13-10-2017 Test event
> 17-11-2017 Test event
> 15-12-2017 Test event
>
> Some of these dates are correct e.g. 14-04-2017 is the second Friday of
> April 2017,
>
> however 17-02-2017 is the Third Friday, the expected result is 10-02-2017
>
>
> I would appreciate any help, I'm baffled :-)
>
>
> Kind regards,
>
>
> Andrew Martin
>
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> use DateTime;
> use DateTime::Event::Recurrence;
> my $year=2017;
> my $event="Test event";
>
> my $dt1 = DateTime->new( year   => $year,
>  month  => 1,
>  day=> 1,
>);
>
> my $dt2 = DateTime->new( year   => $year,
>  month  => 12,
>  day=> 31,
>);
>
> my $set = DateTime::Event::Recurrence->monthly( weeks => 2, days =>5
> );
> my @days = $set->as_list( start => $dt1, end => $dt2 );
>
> foreach my $d (@days){
> print $d->dmy . " $event\n";
> }
>
>


Re: DateTime::Spanset doc typo on cpan

2016-05-17 Thread Flavio S. Glock
DateTime::Set 0.37 in CPAN has a more consistent API:
- max() and end() are exactly the same;
- min() and start() are exactly the same;
- docs and tests are updated

2016-05-17 10:14 GMT+02:00 Flavio S. Glock <fgl...@gmail.com>:
> min() and start(), and max() and end() do exactly the same thing.
>
> DateTime::SpanSet has it right (implemented and documented).
>
> DateTime::Span has it implemented, but not documented (the example should 
> work).
>
> DateTime::Set has min() and max(), but start() and end() are not implemented.
>
> The docs are also inconsistent, this needs a review:
>
> "It is also possible that these methods may return a
> scalar containing infinity or negative infinity."
>
> "It is also possible that these methods
> may return a C or
> C object."
>
>
>
> 2016-05-17 9:42 GMT+02:00 Vincent Berger <i...@vberger.com>:
>> Hi,
>> thanks for your package !
>>
>> according to spanset doc on span
>> http://search.cpan.org/~fglock/DateTime-Set-0.3600/lib/DateTime/SpanSet.pm
>> iterator section
>>
>> $iter = $spanset->iterator;
>> while ( $dt = $iter->next ) {
>> # $dt is a DateTime::Span
>> print $dt->min->ymd;   # first date of span
>> print $dt->max->ymd;   # last date of span
>> }
>>
>>
>> but max and min are not Span functions
>>
>> you mean
>> print $dt->start->ymd
>> print $dt->end->ymd;
>> isn't it ?
>>
>> have a good day
>> Vincent
>>


Re: DateTime::Spanset doc typo on cpan

2016-05-17 Thread Flavio S. Glock
min() and start(), and max() and end() do exactly the same thing.

DateTime::SpanSet has it right (implemented and documented).

DateTime::Span has it implemented, but not documented (the example should work).

DateTime::Set has min() and max(), but start() and end() are not implemented.

The docs are also inconsistent, this needs a review:

"It is also possible that these methods may return a
scalar containing infinity or negative infinity."

"It is also possible that these methods
may return a C or
C object."



2016-05-17 9:42 GMT+02:00 Vincent Berger :
> Hi,
> thanks for your package !
>
> according to spanset doc on span
> http://search.cpan.org/~fglock/DateTime-Set-0.3600/lib/DateTime/SpanSet.pm
> iterator section
>
> $iter = $spanset->iterator;
> while ( $dt = $iter->next ) {
> # $dt is a DateTime::Span
> print $dt->min->ymd;   # first date of span
> print $dt->max->ymd;   # last date of span
> }
>
>
> but max and min are not Span functions
>
> you mean
> print $dt->start->ymd
> print $dt->end->ymd;
> isn't it ?
>
> have a good day
> Vincent
>


Re: Having a strange issue with DateTime::Event::Recurrence under Apache...

2016-02-11 Thread Flavio S. Glock
debugging here - I've written this:

---
use DateTime;
use DateTime::Event::Recurrence;

my $startDate = DateTime->new(
year   => 2016,
month  => 2,
day=> 10,
hour   => 17,
minute => 51,
second => 31,
nanosecond => 123456,
time_zone  => 'America/Chicago',
);
my $count= 15;
my $startDay = DateTime->from_object( object => $startDate
)->truncate( to => 'day' );
my $iterator = DateTime::Event::Recurrence->weekly( days => [ 1 .. 5 ]
)->iterator(
after => DateTime->from_object(
object => $startDay
),
);
my @result = ();
while ( $count-- ) {
my $date = $iterator->next;
print "$date ", $date->day_of_week(), "\n";
}
---

troubleshooting steps:

I would try again without calling isHoliday($date) inside the loop.
This is to rule out that $date is being modified.

Alternately, specify a bounded recurrence (one with start and end
dates). This is to force precalculation of the set, before the
iterator starts. For example, using DateTime::Event::ICal:

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

my $startDate = DateTime->new(
year   => 2016,
month  => 2,
day=> 10,
hour   => 17,
minute => 51,
second => 31,
nanosecond => 123456,
time_zone  => 'America/Chicago',
);
my $startDay = DateTime->from_object( object => $startDate
)->truncate( to => 'day' )->add( days => 1 );
my $iterator = DateTime::Event::ICal->recur(
dtstart => $startDay,
freq=> 'weekly',
byday   => [ "mo", "tu", "we", "th", "fr" ],
count   => 15,
)->iterator();
my @result = ();
while ( my $date = $iterator->next ) {
print "$date ", $date->day_of_week(), "\n";
}
---

please let me know what you get.

Flávio


2016-02-10 19:19 GMT+01:00 Nicholas Schubach :
> To whom it may concern,
>
> I have what I think is a simple couple methods for estimating delivery dates
> (We are a custom printing shop and build in padding to allow for acquire and
> printing then give the customer an estimate on how many days we can complete
> and ship):
>
> sub calculateOrderDeliveryDate
> {
> my ($self, $orderDate, $serviceDays) = @_;
>
> warn Dumper("$orderDate --- $serviceDays");
>
> my @workingDays = $self->_getWorkingDays($orderDate, max (25,
> $serviceDays)); # Optimize search to 25 days out...
>
> return $workingDays[$serviceDays];
> }
>
> sub _getWorkingDays
> {
> my ($self, $startDate, $count) = @_;
> my $startDay = DateTime->from_object( object => $startDate )->truncate(
> to => 'day' );
> my $iterator = DateTime::Event::Recurrence->weekly( days => [1..5]
> )->iterator(
> after => DateTime->from_object( object => $startDay ),
> );
>
> my @result = ();
>
> while ($count > scalar @result)
> {
> my $date = $iterator->next;
> warn Dumper("$date -> ");
> if ($date && !isHoliday($date)) {
> push @result, $date;
> }
> }
>
> return \@result;
> }
>
> Which when called using (Local and server):
>
> perl -e "use DateTime; use Util::Dates;
> Util::Dates->calculateOrderDeliveryDate(DateTime->now(), 7);"
>
> Logs out:
>
> $VAR1 = '2016-02-10T17:51:31 --- 7';
> $VAR1 = '2016-02-12T00:00:00 -> ';
> $VAR1 = '2016-02-15T00:00:00 -> ';
> $VAR1 = '2016-02-16T00:00:00 -> ';
> $VAR1 = '2016-02-17T00:00:00 -> ';
> $VAR1 = '2016-02-18T00:00:00 -> ';
> $VAR1 = '2016-02-19T00:00:00 -> ';
> $VAR1 = '2016-02-22T00:00:00 -> ';
> $VAR1 = '2016-02-23T00:00:00 -> ';
> $VAR1 = '2016-02-24T00:00:00 -> ';
> $VAR1 = '2016-02-25T00:00:00 -> ';
> $VAR1 = '2016-02-26T00:00:00 -> ';
> $VAR1 = '2016-02-29T00:00:00 -> ';
> $VAR1 = '2016-03-01T00:00:00 -> ';
> $VAR1 = '2016-03-02T00:00:00 -> ';
> $VAR1 = '2016-03-03T00:00:00 -> ';
> $VAR1 = '2016-03-04T00:00:00 -> ';
> $VAR1 = '2016-03-07T00:00:00 -> ';
> $VAR1 = '2016-03-08T00:00:00 -> ';
> $VAR1 = '2016-03-09T00:00:00 -> ';
> $VAR1 = '2016-03-10T00:00:00 -> ';
> $VAR1 = '2016-03-11T00:00:00 -> ';
> $VAR1 = '2016-03-14T00:00:00 -> ';
> $VAR1 = '2016-03-15T00:00:00 -> ';
> $VAR1 = '2016-03-16T00:00:00 -> ';
> $VAR1 = '2016-03-17T00:00:00 -> ';
>
> Which is what I want.
>
> When running the same code under an Apache web request on the server, the
> Apache error log file contains:
>
> [Wed Feb 10 12:49:32 2016] main.cgi: $VAR1 = '2016-02-10T12:49:32 --- 7';
> [Wed Feb 10 12:49:32 2016] main.cgi: $VAR1 = '2016-02-11T00:00:00 -> ';
> [Wed Feb 10 12:49:32 2016] main.cgi: $VAR1 = '2016-02-15T00:00:00 -> ';
> [Wed Feb 10 12:49:32 2016] main.cgi: $VAR1 = '2016-02-19T00:00:00 -> ';
> [Wed Feb 10 12:49:32 2016] main.cgi: $VAR1 = '2016-02-22T00:00:00 -> ';
> [Wed Feb 10 12:49:32 2016] main.cgi: $VAR1 = '2016-02-26T00:00:00 -> ';
> [Wed Feb 10 12:49:32 2016] main.cgi: $VAR1 = '2016-02-29T00:00:00 -> ';
> [Wed Feb 10 12:49:32 2016] main.cgi: $VAR1 = '2016-03-04T00:00:00 -> ';
> [Wed Feb 10 12:49:32 2016] main.cgi: $VAR1 = '2016-03-07T00:00:00 -> ';
> [Wed Feb 10 12:49:32 2016] main.cgi: 

Re: Determine size of a DateTime::SpanSet?

2013-09-04 Thread Flavio S. Glock
You can use as_list() to transform the SpanSet into a list of Spans, and
then count the Spans:

  print number of spans: , scalar($s1-as_list);


2013/9/2 Andreas Isberg andr...@isberg.se

 Hi,

 I'm looking for a way to find the size of a DateTime::SpanSet, i.e. the
 number of DateTime:Span objects in it.

 I'm not looking for a DateTime::Duration object, as the size() method
 returns.

 Kind regards,
 Andreas




Re: Issue with DateTime::Span-from_datetime_and_duration()

2013-08-27 Thread Flavio S. Glock
I've uploaded DateTime-Set-0.32 to cpan.

The idea was that you would specify 'end' and a negative duration, like:

DateTime::Span-from_datetime_**and_duration(
end  = DateTime-now(),
hours   = -24
)

but that would not work because of a bug in 0.31 or before.

The new version ignores the signal of the duration, and it does the right
thing depending on which other endpoint is specified.

diff:
https://github.com/fglock/DateTime-Set/commit/83350c3e99455b5cbd0d2c158b0b7168b5c9908e

Flávio S. Glock

2013/8/27 David Pottage d.pott...@cv-library.co.uk

 Hello

 I am attempting to create a number of DateTime::Span objects for the past
hour, past 24 hours, past week etc. The code I am using looks like this:

 my $last24hours = DateTime::Span-from_datetime_and_duration(
 end  = DateTime-now(),
 duration = DateTime::Duration-new( hours = 24 ),
 );

 The code is not working as expected. Instead, I am getting a 24 hour time
span from now into the future rather than into the past.

 I have had a peek at the source code for from_datetime_and_duration(),
and it looks like it always adds the duration to the supplied DateTime
regardless of weather it is supplied as a start or end.

 Is this a bug? I can supply a test case or patch if necessary.

 --
 David Pottage
 CV Library Ltd.



Re: DateTime segments in series: Is there prior art?

2013-08-11 Thread Flavio S. Glock
http://search.cpan.org/dist/DateTime-Set/lib/DateTime/SpanSet.pm

next() and previous() can be used to determine whether a given point
in time falls between, before, or after the segments.

intersects() can tell whether a new segment would intersect existing segments.

2013/8/11 James E Keenan jk...@verizon.net:
 I need to use DateTime functionality and would like to know
 if the particular functionality I need already exists on
 CPAN.

 I need to construct a series of time segments which do not
 overlap but which do not need to be contiguous.  Each
 segment is defined by a start date which is part of the
 segment and by an end date which is the first moment in time
 after the segment's conclusion.

 Example:

 2013-01-01 00:00:00
 2013-02-01 00:00:00

 2013-03-01 00:00:00
 2013-04-01 00:00:00

 2013-04-01 00:00:00
 2013-04-15 00:00:00

 The above would represent a series of 3 segments consisting,
 in human speak, of January 2013, March 2013 and the first 14
 days of April 2013.  The first two segments are not
 contiguous; the second and third are.

 I am permitted to create additional segments before, between
 or after existing segments provided that they do not overlap
 any existing segment.  I can therefore add any of the
 following segments:

 2012-12-15 00:00:00
 2013-01-01 00:00:00

 2013-02-01 00:00:00
 2013-03-01 00:00:00

 2013-04-15 00:00:00
 2013-04-16 00:00:00

 ... but I am not permitted to add either of these segments:

 2013-02-15 00:00:00
 2013-03-15 00:00:00

 2013-04-01 00:00:00
 2013-04-08 00:00:00

 This means that whether initially creating, or subsequently
 updating the series, I must always confirm that a given
 segment does not overlap an existing segment.

 Once I have built an object representing a series, I need
 one or more methods to determine whether a given point in
 time:

 * falls within a particular segment -- in which case that
 segment is identified;

 * falls before the first segment, which is then identified;

 * falls between two segments, in which both of those are
 identified; or

 * falls after the last segment, which is then identified.

 Can you tell me whether prior art exists for this?

 Thank you very much.
 Jim Keenan


Re: Computation time on 'contains' for SpanSets

2010-12-02 Thread Flavio S. Glock
Working with a smaller, bounded subset might help:

# reduce the working set size by intersecting with a smaller span
$total_span_set = $total_span_set-intersection(
  DateTime::Span-new(
start  = DateTime-new( year = 2003, month = 1, day = 1 ),
before = DateTime-new( year = 2003, month = 3, day = 1 )
  )
);

Also changing the set time zone inside a loop can be expensive.
It would be better to move the call to $dt_set-set_time_zone() to
outside of the loops.

Flávio S. Glock

2010/12/1 Per-Olof Jensen per.jen...@bolderthinking.com:
 I've been running into the issue of having a SpanSet being incredibly slow
 when doing a -contains on a DateTime-now object.  I've tried spreading the
 spanset into an array of spans.  That becomes much faster, but only if there
 is no time zone set on those spans.  The moment I put time zones on those
 'not unioned' spans I get a massive slowdown in computation time.  This is
 going into a large scale project, and I was hoping that this feature would
 be able to be used since it does exactly what I need it to do!

 Our goal is to take a group of spans and check if the time right now is
 within each span (basically a daily schedule across the globe).

 Here's a test program illustrating the problem I'm having.  I'm just
 wondering if there is any way to make the -contains faster.


 #!/usr/bin/perl

 use DateTime::Event::Recurrence;
 use DateTime::SpanSet;
 use DateTime::Infinite;
 use DateTime::Set;
 use DateTime;

 my ($total_span_set, $start, $end, $spanset);
 my @array;
 my %tzhash = (
    '1' = 'America/Halifax',
    '2' = 'America/New_York',
    '3' = 'America/Chicago',
    '4' = 'America/Denver',
    '5' = 'America/Los_Angeles',
    '6' = 'America/Nome',
    '7' = 'Pacific/Honolulu',
    '8' = 'Asia/Tokyo',
 );

 $x = 7;

 while ($x  0 ){

 # Make the set representing the work start times: M-F 9:00 and 13:00
 $start = DateTime::Event::Recurrence-weekly
             ( days = $x%6+1, hours = 00 , minutes = 00);
 # Make the set representing the work end times: M-F 12:00 and 17:00
 $end   = DateTime::Event::Recurrence-weekly
             ( days = $x%6+1, hours = 23, minutes = 59);

 # Build a spanset from the set of starting points and ending points
 $spanset = DateTime::SpanSet-from_sets
                ( start_set = $start,
                  end_set   = $end );

 if ($total_span_set){$total_span_set = $total_span_set-union($spanset)}
 else {$total_span_set = $spanset}
 push(@array, $spanset);
 $x--;
 }
 # Iterate from Thursday the 3rd to Monday the 6th
 my $it = $spanset-iterator
           (start  =
            DateTime-new(year = 2003, month = 1, day = 3),
            before =
            DateTime-new(year = 2003, month = 1, day = 7));

 while (my $span = $it-next) {
    my ($st, $end) = ($span-start(), $span-end());
    print $st-day_abbr,  , $st-hour,  to , $end-hour, \n;
 }

 my $dt = DateTime-new(year = 2003, month = 2, day = 11, hour = 11);


 my $timer = DateTime-now;

 #Here I'm using the first way.  Using a spanet seems very slow on 'contains'
 regardless of having a timezone set or not for the span
 my $x = 3;
 while( $x ){
    $dt-set_time_zone($tzhash{$x%6 + 1});
    #Setting a time zone to the SpanSet doesn't seem to affect search time
    $total_span_set-set_time_zone($tzhash{2});
    if ($total_span_set-contains( $dt )){
        print Found time! \n;
    }
 }
 $result = $timer - DateTime-now;
 print Total time : .$result-seconds.\n;


 #An array of spans, this seems to be very fast without timezones set
 $timer = DateTime-now;
 $x = 3;
 while( $x ){

    foreach(@array){
        #Setting a time zone to the SpanSet/Spans really hoses search time
        $_-set_time_zone($tzhash{2});
        if ($_-contains( $dt )){
            print Found time\n;
        }
    }
    $x--;
 }

 $result = $timer - DateTime-now;
 print Total time : .$result-seconds.\n;



 --
 Per Jensen
 Bolder Thinking - Software Developer



Re: [rt.cpan.org #63380]

2010-11-27 Thread Flavio S. Glock
2010/11/27 Philip Kime via RT bug-datet...@rt.cpan.org:

 It seems that it's impossible to instantiate an object with missing 
 information even when it's
 allowed by the format. Using DateTime::Format::ISO8601 I can instantiate

 -new('2003')

 which is allowed by ISO8601 but then DateTime applies a default month and

 -month

 gives 01

 so it's impossible to distinguish whether the date passed was 2003 or  
 2003-01-01, for
 example. I would have expected -month to return undef for the former but 
 it defaults to 01
 and I can't find a way to prevent this. Seems the same also in every other 
 date module I have
 tried.

Have you looked at DateTime::Incomplete?

http://search.cpan.org/dist/DateTime-Incomplete/lib/DateTime/Incomplete.pm

Flávio S. Glock


Re: Recurring DateTimes

2010-09-02 Thread Flavio S. Glock
Please take a look at the 'week_start_day' options:

http://search.cpan.org/~fglock/DateTime-Event-Recurrence-0.16/lib/DateTime/Event/Recurrence.pm#The_%22week_start_day%22_Parameter

The week_start_day represents how the 'first week' of a period is calculated:

mo - this is the default. The first week is one that starts in
monday, and has the most days in this period.

tu, we, th, fr, sa, su - The first week is one that starts
in this week-day, and has the most days in this period. Works for
weekly and yearly recurrences.

1tu, 1we, 1th, 1fr, 1sa, 1su - The first week is one that
starts in this week-day, and has all days in this period. This works
for weekly(), monthly() and yearly() recurrences.

---

I hope it helps,

Flavio S. Glock

2010/9/1 Jon Bjornstad jbjorns...@vindicia.com:
 use DateTime::Event::Recurrence;

 # Second Tuesday of every month:
 #
 my $set = DateTime::Event::Recurrence-monthly(
  weeks = 2,
  days = 2
 );
 my $it = $set-iterator(start = DateTime-now());
 for (1 .. 10) {
    my $dt = $it-next();
    print $dt\n;
 }

 2010-09-14T00:00:00
 2010-10-12T00:00:00
 2010-11-09T00:00:00
 2010-12-14T00:00:00
 2011-01-11T00:00:00
 2011-02-15T00:00:00
 2011-03-15T00:00:00
 2011-04-12T00:00:00
 2011-05-10T00:00:00
 2011-06-14T00:00:00

 This correctly prints the remaining second Tuesdays for 2010
 but in 2011 it includes Feb 15th which is the 3rd Tuesday.
 What's up with that?




Re: DateTime::Span : Setter for start_is_open/end_is_open

2010-07-15 Thread Flavio S. Glock
hi Samuel,

Yes, there is a set operation that removes from the set:

   use DateTime;
   use DateTime::Span;
   my $dt1 = DateTime-new(year = 2009, month = 1, day = 12, hour
= 1, minute = 0, second = 0);
   my $dt2 = DateTime-new(year = 2009, month = 1, day = 12, hour
= 6, minute = 0, second = 0);
   my $span = DateTime::Span-from_datetimes(start = $dt1, end = $dt2);

   # $span2 is just like $span, but the 'end' is open
   my $span2 = $span-complement($dt2);

complement() is available both in DateTime::Span and DateTime::SpanSet

- Flávio S. Glock

2010/7/13 Samuel DUPOND samsam...@gmail.com:
 Hi guys,

 I'd like to know if there is a way to set the start_is_open 
 end_is_open for a DateTime::Span object.

 Right now, as a workaround, I have to remove it from a span set, clone the
 removed span object and set the start/after/end/before as I want, and add it
 back to the span set.

 Thanks in advance,

 Samuel



Re: Span subclass in SpanSet

2010-05-14 Thread Flavio S. Glock
This is a case where DateTime::Event::Spreadsheet might have been useful.

DateTime::Event::Spreadsheet never went to CPAN, but it can be
downloaded from sourceforge (links below).

DT::Spreadsheet is a special case of DateTime::SpanSet, which stores
all information in 'cells' - such as:

my @matched_cells = $dtes-intersects( $base_date );

There is a lot more functionality in this little module, please take a
look at the tests.



Main module:
http://perl-date-time.svn.sourceforge.net/viewvc/perl-date-time/modules/DateTime-Event-Spreadsheet/trunk/lib/DateTime/Event/Spreadsheet.pm

Tests:
http://perl-date-time.svn.sourceforge.net/viewvc/perl-date-time/modules/DateTime-Event-Spreadsheet/trunk/t/

All files:
http://perl-date-time.svn.sourceforge.net/viewvc/perl-date-time/modules/DateTime-Event-Spreadsheet/trunk/

2010/5/14 Rick Measham r...@measham.id.au:
 On 14/05/2010 9:03 AM, Sean Robinson wrote:

 Has anyone used DateTime and friends to find scheduling conflicts and been
 able to identify the offending events without walking a list of Spans?


 A few years back I was in the same place you are right now. Have a look
 through the archive for my work on the catholic liturgical calendar: It has
 many rules about conflicts. I was planning on using DateTime to work out
 when a particular hol[iy]day was in a given year. To do that I was going to
 put everything into spans and sets in priority order, then use conflicts to
 move particluar feasts. Finally I'd have a spanset for the whole year. Each
 span in that set would then be able to return which holy day it was. Once
 that was set up, I could pass in a date and check for a 'conflict' in order
 to determine on which holy day that date fell.



Re: [Fwd: DateTime::Calendar::Hebrew-0.04 errors]

2010-02-18 Thread Flavio S. Glock
2010/2/16 Raphael Mankin r...@mankin.org.uk:
 t/clone.t .. Name main::Dumper used only once: possible typo
 at t/clone.t line 25.
 Can't locate object method is_floating via package floating (perhaps
 you forgot to load floating?)
 at /usr/lib/perl5/vendor_perl/5.8.8/i686-linux/DateTime.pm line 508.

same problem here (sorry, no fix)

Flavio S. Glock


Re: Does event fall within weekly recurring range?

2010-01-04 Thread Flavio S. Glock
how about:
---
#!/usr/bin/perl
use strict;
use warnings;
use DateTime::Format::ICal;

# A file is to be processed if it arrives on the system anytime
# between Friday midnight and Wednesday 8:00 pm.

my $ical_start = 'FREQ=WEEKLY;BYDAY=SA;BYHOUR=0';
my $ical_end   = 'FREQ=WEEKLY;BYDAY=WE;BYHOUR=8';

my $dt_set = DateTime::SpanSet-from_sets(
start_set = DateTime::Format::ICal-parse_recurrence( recurrence
= $ical_start ),
end_set   = DateTime::Format::ICal-parse_recurrence( recurrence
= $ical_end ) );

my $dt = DateTime-new(
   year   = 2010,
   month  = 1,
   day= 4,
);
$dt_set-contains( $dt )
? print $dt is in range\n
: print $dt is not in range\n;

$dt = DateTime-new(
   year   = 2010,
   month  = 1,
   day= 8,
);
$dt_set-contains( $dt )
? print $dt is in range\n
: print $dt is not in range\n;
---

Flávio S. Glock

2010/1/3 James E Keenan jk...@verizon.net:

 The attached file, zinspan.pl, is my first attempt at using DateTime to
 solve a practical problem.  I am looking for feedback both on the program's
 validity and on whether there is the making of a new DateTime module in it.

 Problem:  Suppose that a 'week' can begin at an arbitrarily chosen day of
 the week and time of day.  Suppose further that that week can be divided
 into two subspans:  one in which an event is permitted to occur, and the
 other in which the event is not permitted to occur.  Write a function that
 returns true if the event's date is in the permitted subspan and false if it
 is in the forbidden subspan.

 Example:  A file is to be processed if it arrives on the system anytime
 between Friday midnight and Wednesday 8:00 pm.   The file has arrived. Is it
 okay to process it?

 Thank you very much.
 Jim Keenan


Re: DateTime::Event::Recurrence questions

2009-12-18 Thread Flavio S. Glock
It is not a bug, but it depends on what you expect the first week of
the month to be. You can play with the 'week_start_day' parameter to
get the right week.

The module DateTime::Event::ICal is probably a better choice for you,
since it defaults to the behaviour you expect:

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

my ($start) = 1257051600;
my ($end) = 1283058000;
my ($start_dt) = DateTime-from_epoch(epoch = $start);
my ($end_dt) = DateTime-from_epoch(epoch = $end);

my ($set) = DateTime::Event::ICal-recur(freq = 'monthly', byday = ['2tu']);

my ($iterator) = $set-iterator(start = $start_dt, end = $end_dt);

while (my $dt = $iterator-next) {
 printf %s (%s)\n, scalar gmtime $dt-epoch, $dt-weekday_of_month;
}
---
Tue Nov 10 00:00:00 2009 (2)
Tue Dec  8 00:00:00 2009 (2)
Tue Jan 12 00:00:00 2010 (2)
Tue Feb  9 00:00:00 2010 (2)
Tue Mar  9 00:00:00 2010 (2)
Tue Apr 13 00:00:00 2010 (2)
Tue May 11 00:00:00 2010 (2)
Tue Jun  8 00:00:00 2010 (2)
Tue Jul 13 00:00:00 2010 (2)
Tue Aug 10 00:00:00 2010 (2)


2009/12/18 Frank Sheiness synde...@gmail.com:
 Hello,

 The manpage provides the example:
 # second tuesday of every month
 my $set = DateTime::Event::Recurrence-monthly( weeks = 2, days = 2 );

 However, if I do this:

 use DateTime::Event::Recurrence;

 my ($start) = 1257051600;
 my ($end) = 1283058000;
 my ($start_dt) = DateTime-from_epoch(epoch = $start);
 my ($end_dt) = DateTime-from_epoch(epoch = $end);

 my ($set) = DateTime::Event::Recurrence-monthly(weeks = 2, days = 2);

 my ($iterator) = $set-iterator(start = $start_dt, end = $end_dt);

 while (my $dt = $iterator-next) {
  printf %s (%s)\n, scalar gmtime $dt-epoch, $dt-weekday_of_month;
 }

 I get the following output:

 Tue Nov 10 00:00:00 2009 (2)
 Tue Dec 15 00:00:00 2009 (3)
 Tue Jan 12 00:00:00 2010 (2)
 Tue Feb  9 00:00:00 2010 (2)
 Tue Mar  9 00:00:00 2010 (2)
 Tue Apr 13 00:00:00 2010 (2)
 Tue May 11 00:00:00 2010 (2)
 Tue Jun 15 00:00:00 2010 (3)
 Tue Jul 13 00:00:00 2010 (2)
 Tue Aug 10 00:00:00 2010 (2)

 In December and June (months that begin on Tuesday), the event shows up on
 the third weekday of the month instead of the second.  Note that you get the
 same behavior for any value of days in the set.  If I use 3 for Wednesday,
 I'll get the second Wednesday except for months that begin on Tuesday.  Is
 this a bug or am I doing something incorrectly?  I'm using D::E::R v0.16.

 Thanks,
 Frank



Re: format_recurrence and until

2009-11-17 Thread Flavio S. Glock
This is now fixed in DateTime-Event-ICal-0.10

# RRULE:FREQ=DAILY;UNTIL=20091117T174636Z

thanks for reporting!
Flávio S. Glock

2009/11/16 Nick Spacek nick.spa...@gmail.com:
 Just something I threw together:

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

 my $dt = DateTime-now;
 my $span = DateTime::Event::ICal-recur( freq = 'daily', until = $dt );

 DateTime::Format::ICal-format_recurrence( $span );
 # prints: RRULE:FREQ=DAILY;UNTIL=2009-11-16T20:24:02

 On Mon, Nov 16, 2009 at 4:16 PM, Flavio S. Glock fgl...@gmail.com wrote:

 Would you have a small test script that shows the problem?

 I suspect it can be a problem in DateTime::Event::ICal-_param_str(),
 which is used to stringify the parameters when a recurrence is
 created. It uses the datetime() method, which outputs in ISO format.

 thanks
 Flávio S. Glock

 2009/11/16 Nick Spacek nick.spa...@gmail.com:
  Hi folks,
 
  I was trying to use format_recurrence from DateTime::Format::ICal today
  with
  a parameter specified to until when I discovered that the resulting
  string
  does not correctly format the date. It seems to come out in ISO format
  (that
  is, %Y-%m-%dT%h:%m:%s, I think) instead of ICal format.
 
  The string cannot be parsed (obviously I guess) by
  DateTime::Format::ICal
  either.
 
  The recurrence tests for DateTime::Format::ICal do not check the
  format_recurrence method when using the 'until' parameter, though they
  do
  check that parsing recurrences that have UNTIL work.
 
  Thanks.
  Nick Spacek
 




Re: format_recurrence and until

2009-11-16 Thread Flavio S. Glock
Would you have a small test script that shows the problem?

I suspect it can be a problem in DateTime::Event::ICal-_param_str(),
which is used to stringify the parameters when a recurrence is
created. It uses the datetime() method, which outputs in ISO format.

thanks
Flávio S. Glock

2009/11/16 Nick Spacek nick.spa...@gmail.com:
 Hi folks,

 I was trying to use format_recurrence from DateTime::Format::ICal today with
 a parameter specified to until when I discovered that the resulting string
 does not correctly format the date. It seems to come out in ISO format (that
 is, %Y-%m-%dT%h:%m:%s, I think) instead of ICal format.

 The string cannot be parsed (obviously I guess) by DateTime::Format::ICal
 either.

 The recurrence tests for DateTime::Format::ICal do not check the
 format_recurrence method when using the 'until' parameter, though they do
 check that parsing recurrences that have UNTIL work.

 Thanks.
 Nick Spacek



ANNOUNCE: DateTime::Set 0.28

2009-07-19 Thread Flavio S. Glock
DateTime::Set 0.28   2009-07-19
- optimized DateTime::Set-as_list().
  This works around a segfault reported by Nils Grunwald.
  http://rt.cpan.org/Public/Bug/Display.html?id=47945

Flávio S. Glock


Re: [rt.cpan.org #47691] 29 feb 2009 - to_datetime fails...

2009-07-08 Thread Flavio S. Glock
DateTime::Incomplete

0.04  2009-07-08
- to_datetime() failed when the current year is a non-leap year and
  the incomplete date is a leap day,
  bug reported by Alexandre Masselot.

Flávio S. Glock

2009/7/8 Alexandre Masselot via RT bug-datetime-incompl...@rt.cpan.org:
 Wed Jul 08 05:43:35 2009: Request 47691 was acted upon.
 Transaction: Ticket created by ALEXMASS
       Queue: DateTime-Incomplete
     Subject: 29 feb 2009 - to_datetime fails...
   Broken in: (no value)
    Severity: Important
       Owner: Nobody
  Requestors: alexandre.masse...@genebio.com
      Status: new
  Ticket URL: https://rt.cpan.org/Ticket/Display.html?id=47691 


 Hi Flavio

 I'm using your module with pleasure, but I have a little concern.

 we are in 2009. If I make the test
 my $dti = DateTime::Incomplete-new( month = 2, day = 29, year=2000);
 ok($dti-to_datetime(), 29 feb 2000);

 I get...
 Invalid day of month (day = 29 - month = 2 - year = 2009)
  at /Library/Perl/5.8.8/DateTime/Incomplete.pm line 639

 looking around line 639
    for $key ( breverse @FIELDS_SORTED/b )
    {
        $value = $self-{has}{$key};
        next unless defined $value;
        if ( $key eq 'time_zone' )
        {
            $result-set_time_zone( $value );
            next;
        }
        $result-set( $key = $value );
    }

 and the year is set at the end of the process, thus is 2009 when 29th of
 feb is set = error

 I you wrote the code in 2008, you had not hit that problem...

 cheers
 Alex





Re: RFC: DateTime::Format::Natural and date_only option

2009-06-02 Thread Flavio S. Glock
DateTime::Incomplete uses a 'base' attribute, which you can set to an
arbitrary value:

  base = DateTime-now

  base = DateTime-today

Flávio

2009/5/31 Shane McCarron sh...@aptest.com:
 I would also mention that, at least this year, there are timezones such as
 in Egypt that have no time 00:00:00 on the day when the clocks move ahead -
 their timezone definition goes from 23:59:59 to 01:00:00 on that day.

 Steven Schubiger wrote:

 DateTime::Format::Natural currently does calculate its dates and times
 with an initial DateTime object received by DateTime-now (with timezone
 support). As a consequence thereof, many resulting final DateTime objects
 within DateTime::Format::Natural will retain for units that have not been
 altered the initial values.

 Clayton L. Scott suggested to introduce a date_only option, which would
 ignore (or reset) the time part for date-only strings. I intend to provide
 the names of the units to reset through according metadata entries in the
 grammar class. Later when post-processing data, the units would be
 resetted.

 Some examples from the adjusted and yet unreleased tests:

  * 27/5/1979
     (without date_only: 27.05.1979 01:13:00)        (with date_only:
 27.05.1979 00:00:00)
  * yesterday         (without date_only: 23.11.2006 01:13:08)
        (with date_only: 23.11.2006 00:00:00)
  * next hour
     (without date_only: 24.11.2006 02:13:08)
        (with date_only: 24.11.2006 02:00:00)
  * sunday 11:00     (without date_only: 26.11.2006 11:00:08)        (with
 date_only: 26.11.2006 11:00:00)

 As mentioned above, I concur that it is worthwhile to implement (i.e.,
 set the option per default and leave it open to the user to disable it),
 but I'm a bit unsure that date_only is the most suitable name for this
 new constructor option (given that it does not always reset just all time
 components).

 Suggestions and ideas welcome.

 Thanks,


 --
 Shane P. McCarron                          Phone: +1 763 786-8160 x120
 Managing Director                            Fax: +1 763 786-8180
 ApTest Minnesota                            Inet: sh...@aptest.com





Re: RFC:: DateTime::Span::Common

2009-04-09 Thread Flavio S. Glock
2009/4/8 Rick Measham ri...@isite.net.au:
 Sounds like a job for DateTime::Format::MySQL ..

 $span = DateTime::Span-from_datetimes( start = $dt1, end = $dt2 );
 print DateTime::Format::MySQL-format_span( $span, 'colname' );
 # colname = '2009-04-08 23:22:00' AND colname = '2009-04-09 23:22:00'
[...]
 And could be extended to SpanSets too:
 $spanset = DateTime::SpanSet-from_spans( spans = [ $dt_span, $dt_span ] );
 # (colname = '2009-04-08 23:22:00' AND colname  '2009-04-09 23:22:00') OR
 (colname = '2009-05-08 23:22:00' AND colname  '2009-05-09 23:22:00')

 (Of course, this couldn't be expected to work on infinite or even large
 spansets)

Good idea!

Please use 'format_period' instead of 'format_span' - format_period()
is used by DateTime::Format::ICal API.

format_recurrence() is doable too. DateTime::Event::Recurrence stores
some hints that make stringification possible in several cases.

- Flavio S. Glock


Re: [BUG] Empty spans/spansets have infinite duration?

2009-04-02 Thread Flavio S. Glock
2009/4/2 Anton Berezin to...@tobez.org:
 Hi,

 It's a bit tricky to say which particular module needs to be changed to fix
 this bug, hence I am not using RT for reporting it.  The good part is that
 all candidate modules appear to have the same author.  :-)

 The test case is as follows:

    #! /usr/bin/perl
    use strict;
    use warnings;

    use DateTime;
    use DateTime::Duration;
    use DateTime::Span;
    use Data::Dumper;

    my $bad_s = DateTime-new(year = 2009, month = 1, day = 12, hour = 1, 
 minute = 0, second = 0);
    my $bad_e = DateTime-new(year = 2009, month = 1, day = 12, hour = 6, 
 minute = 0, second = 0);

    my $bad = DateTime::Span-from_datetimes(start = $bad_s, end = $bad_e);
    my $good = $bad-complement;

    my $interest_s = DateTime-new(year = 2009, month = 1, day = 12, hour 
 = 4, minute = 30, second = 0);
    my $interest_e = DateTime-new(year = 2009, month = 1, day = 12, hour 
 = 5, minute = 0, second = 0);

    my $interest = DateTime::Span-from_datetimes(start = $interest_s, end = 
 $interest_e);

    my $r = $interest-intersection($good);

    my $d = $r-duration;
    print Dumper $d;

    my $d0 = DateTime::Duration-new(seconds = 0);
    print Dumper $d0;

 I would certainly expect for the duration $d of the empty set $r to be the
 same duration as $d0, that is, zero seconds.  Instead it behaves more like
 infinity.

This seems to be caused by a previous DateTime::Span fix that went wrong:

eval {
local $SIG{__DIE__};   # don't want to trap this (rt ticket 5434)
$dur = $_[0]-end-subtract_datetime_absolute( $_[0]-start )
};

(start and end are not defined in this case)


 Is that something that you might be interesting in fixing?

yes! thanks for reporting.

Flávio S. Glock

 Thanks,
 \Anton.
 --
 There is no beauty in entropy. -- Eliezer Yudkowsky



Re: [BUG] Empty spans/spansets have infinite duration?

2009-04-02 Thread Flavio S. Glock
Fixed in DateTime::Set 0.27

0.27   2009-04-02
- fixed DateTime::Spanset duration() method.
  Reported by Anton Berezin to...@tobez.org

Flávio S. Glock

2009/4/2 Flavio S. Glock fgl...@gmail.com:
 2009/4/2 Anton Berezin to...@tobez.org:
 Hi,

 It's a bit tricky to say which particular module needs to be changed to fix
 this bug, hence I am not using RT for reporting it.  The good part is that
 all candidate modules appear to have the same author.  :-)

 The test case is as follows:

    #! /usr/bin/perl
    use strict;
    use warnings;

    use DateTime;
    use DateTime::Duration;
    use DateTime::Span;
    use Data::Dumper;

    my $bad_s = DateTime-new(year = 2009, month = 1, day = 12, hour = 1, 
 minute = 0, second = 0);
    my $bad_e = DateTime-new(year = 2009, month = 1, day = 12, hour = 6, 
 minute = 0, second = 0);

    my $bad = DateTime::Span-from_datetimes(start = $bad_s, end = $bad_e);
    my $good = $bad-complement;

    my $interest_s = DateTime-new(year = 2009, month = 1, day = 12, hour 
 = 4, minute = 30, second = 0);
    my $interest_e = DateTime-new(year = 2009, month = 1, day = 12, hour 
 = 5, minute = 0, second = 0);

    my $interest = DateTime::Span-from_datetimes(start = $interest_s, end 
 = $interest_e);

    my $r = $interest-intersection($good);

    my $d = $r-duration;
    print Dumper $d;

    my $d0 = DateTime::Duration-new(seconds = 0);
    print Dumper $d0;

 I would certainly expect for the duration $d of the empty set $r to be the
 same duration as $d0, that is, zero seconds.  Instead it behaves more like
 infinity.

 This seems to be caused by a previous DateTime::Span fix that went wrong:

    eval {
        local $SIG{__DIE__};   # don't want to trap this (rt ticket 5434)
        $dur = $_[0]-end-subtract_datetime_absolute( $_[0]-start )
    };

 (start and end are not defined in this case)


 Is that something that you might be interesting in fixing?

 yes! thanks for reporting.

 Flávio S. Glock

 Thanks,
 \Anton.
 --
 There is no beauty in entropy. -- Eliezer Yudkowsky




Re: DateTime::Format::ICal bug : DTSTART value in recurrences not converted to DateTime

2009-02-18 Thread Flavio S. Glock
This is an intentional feature - DTSTART is not an RRULE component.

An iCalendar text looks like:

 DTSTART:19870405T02
 RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4

reference: http://www.ietf.org/rfc/rfc2445.txt

Flávio S. Glock

2009/2/18 Olivier Mengué olivier.men...@gmail.com:
 Hi,

 I have a problem with this expression (Second wednesday of every month, at
 20:00) that I'm using with DateTime::Format::ICal-parse_recurrence() :
 FREQ=MONTHLY;BYDAY=2WE;DTSTART=20090201T20Z;COUNT=12

 Here is the test case:
 perl -MDateTime::Format::ICal -e
 DateTime::Format::ICal-parse_recurrence(recurrence='FREQ=MONTHLY;BYDAY=2WE;DTSTART=20090201T20Z;COUNT=12')
 The 'start' parameter (20090201t20z) to DateTime::Span::from_datetimes
 was a 'scalar', which is not one of the allowed types: object
  at C:/strawberry/perl/site/lib/DateTime/Span.pm line 37
DateTime::Span::from_datetimes(undef, 'start', '20090201t20z')
 called at C:/strawberry/perl/site/lib/DateTime/Event/ICal.pm line 515
DateTime::Event::ICal::recur('DateTime::Event::ICal', 'freq', 'monthly',
 'byday', 'ARRAY(0x11f805c)', 'dtstart', '20090201t20z') called at
 C:/strawberry/perl/site/lib/DateTime/Event/ICal.pm line 501
DateTime::Event::ICal::recur('DateTime::Event::ICal', 'count', 12,
 'freq', 'monthly', 'byday', 'ARRAY(0x11f805c)', 'dtstart',
 '20090201t20z', ...) called at
 C:/strawberry/perl/site/lib/DateTime/Format/ICal.pm line 173
DateTime::Format::ICal::parse_recurrence(undef, 'recurrence',
 'FREQ=MONTHLY;BYDAY=2WE;DTSTART=20090201T20Z;COUNT=12', 'dtstart',
 'DateTime=HASH(0x11f772c)') called at C:/Documents and
 Settings/omengue/Documents/Eclipse/Test POE Scheduler/test-ical-recur.pl
 line 31


 It looks like a conversion of the string value of dtstart to a DateTime
 object is missing...

 Olivier
 http://o.mengue.free.fr/



Re: http://rt.cpan.org/Public/Bug/Display.html?id=42028

2009-01-09 Thread Flavio S. Glock
Martin:

I just sent Date-Tie 0.19 to CPAN.

I think I've found the bug. It was caused by an infinite loop in
Date-Tie 0.18, which then caused a year-2038 problem. The error
behaviour in ActivePerl was different for some reason.

Please let me know if that fixes the problem.
(attached: Date-Tie 0.19)

thanks!
Flávio

2008/12/31 Martin Labonté martin.labo...@sympatico.ca:
 Hello,

 I submitted the bug #42028. I read your last entry briefly and I tried to
 upgrade Local-Time to 1.1901 but I still have the problem with  Date-Tie
 0.18. Let me know how I could help if needed. There is no urgency as I can
 use Date-Tie 0.17 so I wish that you will have an happy new year in 2009.

 Regards,

 Martin



Date-Tie-0.19.tar.gz
Description: GNU Zip compressed data


ANNOUNCE: DateTime::Set 0.26

2008-12-25 Thread Flavio S. Glock
0.26   2008-12-25

- fixed DateTime::Spanset current() and set_time_zone() methods.
  Report and tests by Elliot Shank.

Flávio S. Glock


Re: Week wraparound recurrences and time zones

2008-12-19 Thread Flavio S. Glock
I've attached a patch for current() and set_time_zone().

There are no tests.

2008/12/19 Elliot Shank p...@galumph.com:
 I now have a case where I'm trying to set up a set of weekly recurrences
 that cover the entire week: if I've got Tuesday at 5pm and Thursday at
 11:30am, there are two SpanSets, on the covers the Tuesday to Thursday range
 and one that covers the Thursday to Tuesday range.  I'm running into
 problems with the degenerate case where there's only one point for the week.
 If I don't set the time zone on the SpanSet, I get what I'm expecting, with
 one exception that I can work around.  However, if I touch the time zone,
 then things go awry, even if I use the intermediary floating time zone
 trick.

 If I don't set the time zone, I get correct results, except for precisely at
 the time of the single anchor, but in that case, only the end is wrong, and
 I can easily work around that.

 If I do set the time zone, pulling the currently effective span from the set
 results in spans that are infinite in both directions.


  With no time zone changes,   now start: 2008-12-15T08:30:00 end:
 2008-12-22T08:30:00
  With no time zone changes,  6:30 start: 2008-12-08T08:30:00 end:
 2008-12-15T08:30:00
  With no time zone changes,  7:30 start: 2008-12-08T08:30:00 end:
 2008-12-15T08:30:00
  With no time zone changes,  8:30 start: 2008-12-15T08:30:00 end:
 inf
  With no time zone changes,  9:30 start: 2008-12-15T08:30:00 end:
 2008-12-22T08:30:00
  With no time zone changes, 10:30 start: 2008-12-15T08:30:00 end:
 2008-12-22T08:30:00
  With no time zone changes, 11:30 start: 2008-12-15T08:30:00 end:
 2008-12-22T08:30:00
   With time zone specified,   now start: -inf end: inf
   With time zone specified,  6:30 start: -inf end: inf
   With time zone specified,  7:30 start: -inf end: inf
   With time zone specified,  8:30 start: -inf end: inf
   With time zone specified,  9:30 start: -inf end: inf
   With time zone specified, 10:30 start: -inf end: inf
   With time zone specified, 11:30 start: -inf end: inf
 With intermediary floating time zone,   now start: -inf end: inf
 With intermediary floating time zone,  6:30 start: -inf end: inf
 With intermediary floating time zone,  7:30 start: -inf end: inf
 With intermediary floating time zone,  8:30 start: -inf end: inf
 With intermediary floating time zone,  9:30 start: -inf end: inf
 With intermediary floating time zone, 10:30 start: -inf end: inf
 With intermediary floating time zone, 11:30 start: -inf end: inf


 -

 use DateTime;
 use DateTime::Event::Recurrence;
 use DateTime::SpanSet;


 my $recurrence =
   DateTime::Event::Recurrence-weekly(
   days = 1, hours = 8, minutes = 30,
   );

 my $base_span_set =
   DateTime::SpanSet
   -from_sets(start_set = $recurrence, end_set = $recurrence);

 dump_end_points(
   $base_span_set,
   'With no time zone changes',
 );
 dump_end_points(
   $base_span_set
   -clone()
   -set_time_zone('America/Chicago'),
   'With time zone specified',
 );
 dump_end_points(
   $base_span_set
   -clone()
   -set_time_zone('floating')
   -set_time_zone('America/Chicago'),
   'With intermediary floating time zone',
 );

 sub dump_end_points {
   my ($span_set, $name) = @_;

   my $format = %36s, %5s start: %s end: %s\n;

   my $span = $span_set-current( DateTime-now() )-span();
   printf $format, $name, 'now', $span-start(), $span-end();

   foreach my $hour (6..11) {
   $span =
   $span_set
   -current(
   DateTime-new(
   year= 2008,
   month   = 12,
   day = 15,
   hour= $hour,
   minute  = 30,
   )
   )
   -span();
   printf $format, $name, $hour:30, $span-start(), $span-end();
   }
 }

--- /Users/flavioglock/projects/datetime/perl-date-time/modules/DateTime-Set/trunk/lib/DateTime/SpanSet.pm	2008-06-21 09:37:43.0 +0200
+++ lib/DateTime/SpanSet.pm	2008-12-19 23:06:33.0 +0100
@@ -85,12 +85,12 @@
 if ( ref($min) )
 {
 $min = $min-clone;
-$min-set_time_zone( $tz );
+$min-set_time_zone( 'floating' );
 }
 if ( ref($max) )
 {
 $max = $max-clone;
-$max-set_time_zone( $tz );
+$max-set_time_zone( 'floating' ); 
 }
 return Set::Infinite::_recurrence-new( $min, $max );
 },
@@ -292,10 +292,30 @@
 sub current {
 my $self = shift;
 
-my $return = $self-intersected_spans( $_[0] );
+my $previous;
+my $next;
+{
+my $min;
+$min = $_[0]-min if UNIVERSAL::can( $_[0], 'union' );
+$min = $_[0] if ! defined $min;
+return undef if ! ref( $min )  $min == INFINITY;
+

Re: Recurrences and daylight savings

2008-12-17 Thread Flavio S. Glock
It's a bug.
You can workaround it by setting the time zone first to 'floating',
and then to 'Asia/Jerusalem':
--
sub show_day_start_and_end {
   my ($day_index, $day_name, $day_of_month) = @_;

   my $span_set =
   DateTime::SpanSet
   -from_sets(
   start_set   =
   DateTime::Event::Recurrence-weekly(
   days = $day_index, hours = 8, minutes = 30,
   ),
   end_set =
   DateTime::Event::Recurrence-weekly(
   days = $day_index, hours = 15, minutes = 30,
   ),
   )
   -set_time_zone('floating')
   -set_time_zone('Asia/Jerusalem');

   my $date =
   DateTime-new(
   year= 2008,
   month   = 3,
   day = $day_of_month,
   hour= 12,
   time_zone = 'Asia/Jerusalem'
   );

   my $span = $span_set-current($date)-span();
   say $day_name start: , $span-start(), ' end: ', $span-end(), '
', $span-end-time_zone-name;
}
-

Tests would be much welcome :)

Flávio S. Glock

2008/12/16  p...@galumph.com:
 I'm seeing unexpected behavior with recurrences on different sides of a 
 daylight savings change.  I'm expecting that I get the same local time of 
 day, regardless of which side I'm on.

 I've been using Jerusalem as a test time zone due to the fact that it goes 
 onto daylight savings on a Friday.  So, in the below sample code, I'm testing 
 last spring's changeover on 2008-3-28.  Since both the Thursday and Friday 
 recurrences start and end at the same times of day, I'm expecting that I 
 should get 8:30am for the start and 3:30pm for the end on both days.  
 However, what I get for output is:

Thursday start: 2008-03-27T08:30:00 end: 2008-03-27T15:30:00
Friday start: 2008-03-28T09:30:00 end: 2008-03-28T16:30:00

 How do I get consistent local times of day?

 -

 DateTime: 0.4305
 DateTime::Event::Recurrence: 0.16
 DateTime::SpanSet: 0.25

 perl 5.10.0

 -

 use DateTime;
 use DateTime::Event::Recurrence;
 use DateTime::SpanSet;

 show_day_start_and_end(4, 'Thursday', 27);
 show_day_start_and_end(5, 'Friday',   28);

 sub show_day_start_and_end {
my ($day_index, $day_name, $day_of_month) = @_;

my $span_set =
DateTime::SpanSet
-from_sets(
start_set   =
DateTime::Event::Recurrence-weekly(
days = $day_index, hours = 8, minutes = 30,
),
end_set =
DateTime::Event::Recurrence-weekly(
days = $day_index, hours = 15, minutes = 30,
),
)
-set_time_zone('Asia/Jerusalem');

my $date =
DateTime-new(
year= 2008,
month   = 3,
day = $day_of_month,
hour= 12,
time_zone = 'Asia/Jerusalem'
);

my $span = $span_set-current($date)-span();
say $day_name start: , $span-start(), ' end: ', $span-end();
 }



Re: What am I not understanding about DateTime::SpanSet::intersects()?

2008-12-13 Thread Flavio S. Glock
The intersects() method returns undef when it can't decide if there is
an intersection.

2008/12/13 Elliot Shank p...@galumph.com:
 In the code below, why do the span sets not intersect when the spans taken
 from them do?

 I've tried this code on both Red Hat 5.2 and on Mac OS X 10.5.

 DateTime: 0.4501
 DateTime::SpanSet: 0.25
 DateTime::Event::Recurrence: 0.16

 ===

 next start 1: 2008-12-17T07:00:00
 next end 1:   2008-12-18T07:00:00
 next start 2: 2008-12-17T17:00:00
 next end 2:   2008-12-18T17:00:00
 spans intersect: yes
 span sets intersect: no

 ===

 use DateTime;
 use DateTime::SpanSet;
 use DateTime::Event::Recurrence;

 my $start_1 = DateTime::Event::Recurrence-weekly(days = 3, hours = 7);
 my $end_1 = DateTime::Event::Recurrence-weekly(days = 4, hours = 7);
 my $span_set_1 = DateTime::SpanSet-from_sets(start_set = $start_1, end_set
 = $end_1);

 my $start_2 = DateTime::Event::Recurrence-weekly(days = 3, hours = 17);
 my $end_2 = DateTime::Event::Recurrence-weekly(days = 4, hours = 17);
 my $span_set_2 = DateTime::SpanSet-from_sets(start_set = $start_2, end_set
 = $end_2);

 my $now = DateTime-now();

 my $span_1 = $span_set_1-next($now);
 my $span_2 = $span_set_2-next($now);

 say 'next start 1: ', $span_1-start();
 say 'next end 1:   ', $span_1-end();
 say 'next start 2: ', $span_2-start();
 say 'next end 2:   ', $span_2-end();

 say 'spans intersect: ', $span_1-intersects($span_2) ? 'yes' : 'no';
 say 'span sets intersect: ', $span_set_1-intersects($span_set_2) ? 'yes' :
 'no';


...
say 'span sets intersect: ', $span_set_1-intersects($span_set_2) ?
'yes' : 'no';
say 'span sets intersect is defined: ', defined
$span_set_1-intersects($span_set_2) ? 'yes' : 'no';
my $span_3 = DateTime::Span-from_datetimes( start =
DateTime-new(year=2001), end = DateTime-ne
w(year=2002) );

say 'span sets intersect: ', $span_2-intersects($span_3) ? 'yes' : 'no';
say 'span sets intersect is defined: ', defined
$span_2-intersects($span_3) ? 'yes' : 'no';

...
span sets intersect: no
span sets intersect is defined: no
span sets intersect: no
span sets intersect is defined: yes

this was probably a poor design decision, and it seems to be undocumented.

Flávio S. Glock


Re: Module submission DateTime::Event::Predict

2008-11-21 Thread Flavio S. Glock
2008/11/21 Dr.Ruud [EMAIL PROTECTED]:
 Flavio S. Glock schreef:

 =head1 CREDITS

 Based on an idea from Steffen Mueller [EMAIL PROTECTED]

 I think that should be Brian Hann:

  Message-ID: [EMAIL PROTECTED]

Patch applied - thanks!

 --
 Affijn, Ruud

 Gewoon is een tijger.


Flávio S. Glock


Re: Module submission DateTime::Event::Predict

2008-11-20 Thread Flavio S. Glock
{
package DateTime::Event::Predict;
use DateTime::Event::ICal;
use strict;

sub new {
my ($class, %params) = @_;
my $dts = DateTime::Set-from_datetimes( dates = $params{dates} );
for my $freq ( qw[ yearly monthly weekly daily hourly minutely
secondly ] ) {
my $dtr = DateTime::Event::ICal-recur( freq = $freq, dtstart
= $params{dates}[0] );
return $dtr if $dtr-contains( $dts );
}
return $dts;
}

}

# SYNOPSIS

# use DateTime::Event::Predict;
use DateTime::Format::ICal;

my $dtr = DateTime::Event::Predict-new( dates = [ DateTime-today,
DateTime-today-add( months = 1 ) ] );

print DateTime::Format::ICal-format_recurrence($dtr);

# note: format_recurrence() doesn't print 'DTSTART', but the
recurrence values are correct

=head1 CREDITS

Based on an idea from Steffen Mueller [EMAIL PROTECTED]

=head1 COPYRIGHT

Copyright (c) 2008 Flavio Soibelmann Glock.
All rights reserved.  This program is free software; you can
redistribute it and/or modify it under the same terms as Perl itself.

=cut


Re: best practice?

2008-10-24 Thread Flavio S. Glock
2008/10/23 Herbert Liechti [EMAIL PROTECTED]:
 Hi all

 I'm currently involved in a project where a ressource

 planning system is developed. We are using the

 datetime.* libs for that purpose.

 Values of occupied ressources

 are stored in a database. For a intersection wether a

 ressource is free or occupied we are using

 DateTime::SpanSet. But now the problem:

 I have to be able to associate a database object

 with a given SpanSet which I create when retrieving

 the data from the database.

 spans:

 [.n.][.n.][.n.]- new reservation

 [.a.][.a.][.a.][.b.][.b.][.c.]  - existing data

 intersection gives conflicts with a  b which is correct
 but i loose the context which of the dt objects belongs
 to which data object.

 First approach was to inherit from DateTime and
 storing object references. But when I intersect_span
 the sets, I'm loosing my references, seems that the dt
 objects are newly created.


That's correct, DateTime sets always return cloned objects.

 How can I solve that problem. If it is helpful I can
 attach the inheritet DateTime code


Sure, that might help.

 Thank you very much for your help and sorry for the
 bad english.

 Regards Herbie


Flávio S. Glock


Re: adding a time to a DT object

2008-09-26 Thread Flavio S. Glock
2008/9/26 Perrin Harkins [EMAIL PROTECTED]:

 The gist of what I wanted to do is this:

 - Take a DT object which has been truncated to day.
 - Take a string like 10:30 AM.
 - Set the time on the DT object according to that string.


how about:

use DateTime::Incomplete;
use DateTime::Format::Strptime;
my $df = DateTime::Format::Strptime-new( pattern = %I:%M %p );
my $di = DateTime::Incomplete-today;

for (qw| 09:15 10:30 11:25 |) {
print $di-to_datetime( base = $df-parse_datetime($_ AM) ), \n;
}

2008-09-26T09:15:00
2008-09-26T10:30:00
2008-09-26T11:25:00

- Flávio S. Glock


Re: Contributing to DateTime::Event

2008-08-27 Thread Flavio S. Glock
2008/8/27 Kristian Flint [EMAIL PROTECTED]:
 Hi everybody,

 I've not been using DateTime for very long and got recommended it by our
 hosting partners, really happy with it etc... But I've come across a
 situation where I want to do something standardish with it and there
 doesn't seem to be any provision for it. The reason I'm mailing the list
 is that I'm amazed no-one has done this before which is leading me to a
 suspicion that there's a good reason why!

 So, what I want to do is get the the Bank Holidays for the UK and a few
 other methods like 'is_this_a_bank_holiday( $dt )' or perhaps something
 like 'number_of_working_days_in( $dt1, $dt2 )' to take into account
 weekends. And so on as the project I'm working on requires.
 Now, the reason I think this is possible is that looking at:
 http://www.berr.gov.uk/employment/bank-public-holidays/index.html
 The dates don't appear to be particularly random (they all have v.simple
 rules) and the only dates I don't really understand, the easter ones,
 I'm planning on using DateTime::Event::Easter to help me out.

 Is there anything obvious anyone can see that I'm missing, or any
 problems with doing this? I'd imagine I'd call this module
 DateTime::Event::BankHolidays::UK|England but I'm getting a bit ahead of
 myself now.

 Ta,

 Kristian


Kristian:

I'd create DateTime::Event::ICal objects for the non-easter dates.
Dt::E::ICal creates DateTime::Set objects, which provide several
methods you might need.
Dt::E::Easter also creates Dt::Set objects, and you can do a 'union'
of sets to complete your calendar.

Please take a look at the docs. I'd be glad to help if you have problems.

Flávio S. Glock


new DateTime::Format module

2008-07-27 Thread Flavio S. Glock
re:
  http://search.cpan.org/dist/DateTime-Format-Span/

This module seems to handle durations, instead of spans.
How about naming it DateTime::Format::Duration instead?

- Flavio S. Glock


Re: DateTime Spanset Calculation

2008-07-20 Thread Flavio S. Glock
2008/7/20 David Gang [EMAIL PROTECTED]:
 Hi All,
 I wrote a script with two cases.
 In the first case the set unites between the spans and in the second set
 it does not unite.
 Can you please explain me what is the difference and how in the first
 case I can bring them to unite ?
 (I am using version 0.25)

 Best regards,
 David

It's a bug in Set::Infinite union().
This bug only affects DateTime::SpanSets.

I've uploaded a fix.
Please install Set::Infinite 0.62 - available in the DateTime
repository, soon at CPAN.

Flávio S. Glock

PS: almost 4 years without bugs :)


Re: DateTime From Solar Longitude

2008-06-22 Thread Flavio S. Glock
2008/6/21 Jaldhar H. Vyas [EMAIL PROTECTED]:
 Given a decimal value for solar longitude (such as from
 DateTime::Util::Astro::Sun::solar_longitude) how would I convert it to a
 DateTime.

 Specifically what I want to do is determine the first new moon after the
 vernal equinox (solar longitude = 0)

how about:

  use DateTime::Event::Lunar;
  use DateTime::Event::SolarTerm;
  my $new_moon = DateTime::Event::Lunar-new_moon();

  my $dt0  = DateTime-today;
  my $eq = DateTime::Event::SolarTerm-next_term_at(
datetime  = $dt0,
longitude = 0,
  );
  print $new_moon-next( $eq ), \n;


Flávio S. Glock


ANNOUNCE: DateTime::Incomplete 0.0301

2008-06-21 Thread Flavio S. Glock
0.0301  2008-06-21
- updated strftime tests, again.

Flávio S. Glock


Re: [rt.cpan.org #34912] Constants for months/weekdays?

2008-04-12 Thread Flavio S. Glock
2008/4/12, Flavio Poletti via RT [EMAIL PROTECTED]:
  Sat Apr 12 08:41:24 2008: Request 34912 was acted upon.
  Transaction: Ticket created by POLETTIX
Queue: DateTime
  Subject: Constants for months/weekdays?
Broken in: 0.42
 Severity: Wishlist
Owner: Nobody
   Requestors: [EMAIL PROTECTED]
   Status: new
   Ticket URL: http://rt.cpan.org/Ticket/Display.html?id=34912 

  Hi,

I think it would be useful to have some constants exported by the
  module to refer to month names and weekdays, like JANUARY, JANUARY_0 and
  so on. Otherwise, it's likely that the users will define such constants
  by themselves (or worse hardcode them), leading to potential bugs.

  I noticed this while reading http://use.perl.org/~Aristotle/journal/36022.


# Reference: http://use.perl.org/~Aristotle/journal/36022

{
#--
# implementation using the ICal module

use DateTime::Event::ICal;
print with ICal\n;
my $first_thursday = DateTime::Event::ICal-recur(
freq = 'monthly',
byday = [ '1th' ]
);
my $fridays = DateTime::Event::ICal-recur(
freq = 'weekly',
byday = [ 'fr' ]
);
my $first_friday = DateTime::Event::ICal-recur(
freq = 'monthly',
byday = [ '1fr' ]
);
my $last_friday = DateTime::Event::ICal-recur(
freq = 'monthly',
byday = [ '-1fr' ]
);

my $dt = DateTime-today;
my $dt_month = DateTime-today-truncate( to = 'month' )-add( months = 1 );

print 'First Friday of this month: ',
   $first_friday-previous( $dt_month ), \n;

print 'Last Friday of this month: ',
   $last_friday-previous( $dt_month ), \n;

print 'The Friday before today: ',
   $fridays-previous( $dt ), \n;

print 'London.pm heretics meeting this month: ',
   $first_thursday-previous( $dt_month ), \n;

print \n;
#--
}


{
#--
# implementation using the Recurrence module
# - requires a little more calculations; more error-prone

use DateTime::Event::Recurrence;
print with Recurrence\n;
my $thursdays = DateTime::Event::Recurrence-weekly( days = [ 'th' ] );
my $fridays   = DateTime::Event::Recurrence-weekly( days = [ 'fr' ] );

my $dt = DateTime-today;

print 'First Friday of this month: ',
   $fridays-next( $dt-clone-truncate( to = 'month' )-subtract(
days = 1 ) ), \n;

print 'Last Friday of this month: ',
   $fridays-previous( $dt-clone-truncate( to = 'month' )-add(
months = 1 ) ), \n;

print 'The Friday before today: ',
   $fridays-previous( $dt ), \n;

print 'London.pm heretics meeting this month: ',
   $thursdays-next( $dt-clone-truncate( to = 'month' )-subtract(
days = 1 ) ), \n;

print \n;
#--
}

# First Friday of this month: 2008-04-04T00:00:00
# Last Friday of this month: 2008-04-25T00:00:00
# The Friday before today: 2008-04-11T00:00:00
# London.pm heretics meeting this month: 2008-04-03T00:00:00


Re: namespace DateTime::BusinessHours

2008-03-15 Thread Flavio S. Glock
2008/3/15, Rick Measham [EMAIL PROTECTED]:

  (NOTE for other DT devs: It would be good if, given a DateTime::Set (or
  DateTime::Set::ICal) you could get the $Nth day .. like the 10th day.
  rather than an iterator and call it $N times or turning the set into a
  list (which in this case is infinite))

DateTime::Event::ICal constructor allows to select the Nth occurrence:

  $dtset = DateTime::Event::ICal-new( , bysetpos = [ 10 ] );

bysetpos is not in the DateTime::Set API, but the infrastructure is
there (in Set::Infinite):

  $set = $set1-select( by = [ 10 ] );

- Flavio S. Glock


Re: Sets, Recurrences, Public Holidays .. Business Days trouble

2008-01-23 Thread Flavio S. Glock
2008/1/22, Rick Measham [EMAIL PROTECTED]:
 The aim is to work out N 'business days' from now.

 Every one defines business days differently, but for me it's Monday to
 Friday skipping public holidays.

 Step 1: Set of every day
 Step 2: Complemented with weekends
 Step 3: Complemented with public holidays

 However, the code I've put together dies in rather nasty ways or runs
 really slowly (change the @events in the grep to @events[1,2])


I simplified the code a bit and it now works.
However, I don't know what is the problem with the original code.

- Flavio S. Glock


business_days.pl
Description: Perl program


Fwd: FAIL DateTime-Incomplete-0.03 amd64-freebsd 6.2-prerelease

2008-01-19 Thread Flavio S. Glock
I tried to fix this test in the last revision, but it seems the test
output is unpredictable:

  #   at t/13strftime.t line 58.
  #  got: 'Di'
  # expected: 'Di.'

Is there a prerequisite Locale version I should require in the Makefile?

thanks
- Flavio S. Glock

-- Forwarded message --
From: [EMAIL PROTECTED] [EMAIL PROTECTED]
Date: 19/01/2008 09:33
Subject: FAIL DateTime-Incomplete-0.03 amd64-freebsd 6.2-prerelease
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]


This distribution has been tested as part of the cpan-testers
effort to test as many new uploads to CPAN as possible.  See
http://testers.cpan.org/

Please cc any replies to [EMAIL PROTECTED] to keep other
test volunteers informed and to prevent any duplicate effort.

--
Dear Flavio Soibelmann Glock,

This is a computer-generated report for DateTime-Incomplete-0.03
on perl-5.8.8, created automatically by CPAN-Reporter-1.0601
and sent to the CPAN Testers mailing list.

If you have received this email directly, it is because the person testing
your distribution chose to send a copy to your CPAN email address; there
may be a delay before the official report is received and processed
by CPAN Testers.

Thank you for uploading your work to CPAN.  However, it appears that
there were some problems with your distribution.  If these results are
not what you expect or if you would like to learn how to avoid FAIL
reports for missing dependencies, unsupported operating systems, etc.,
please consult Notes for CPAN Authors on the CPAN Testers Wiki:
http://cpantest.grango.org

Sections of this report:

* Tester comments
* Program output
* Prerequisites
* Environment and other context

--
TESTER COMMENTS
--

Additional comments from tester:

[none provided]

--
PROGRAM OUTPUT
--

Output from '/usr/bin/make test':

PERL_DL_NONLAZY=1 /usr/local/bin/perl5.8.8 -MExtUtils::Command::MM
-e test_harness(0, 'blib/lib', 'blib/arch') t/*.t
t/02incomplete...ok
t/03base.ok
t/04base_overflowok
t/05datetime.ok
t/13strftime.
#   Failed test '%a'
#   at t/13strftime.t line 58.
#  got: 'Di'
# expected: 'Di.'

#   Failed test '%b'
#   at t/13strftime.t line 58.
#  got: 'Sep'
# expected: 'Sep.'

#   Failed test '%h'
#   at t/13strftime.t line 58.
#  got: 'Sep'
# expected: 'Sep.'
# Looks like you failed 3 tests of 123.
dubious
Test returned status 3 (wstat 768, 0x300)
DIED. FAILED tests 44, 46, 52
Failed 3/123 tests, 97.56% okay
Failed TestStat Wstat Total Fail  List of Failed
---
t/13strftime.t3   768   1233  44 46 52
Failed 1/5 test scripts. 3/235 subtests failed.
Files=5, Tests=235, 10 wallclock secs ( 2.13 cusr +  0.88 csys =  3.02 CPU)
Failed 1/5 test programs. 3/235 subtests failed.
*** Error code 3

Stop in /mnt/i386/usr/local/src/CPAN/build/DateTime-Incomplete-0.03-Molbf4.

--
PREREQUISITES
--

Prerequisite modules loaded:

requires:

Module  Need   Have
--- -- 
DateTime0  0.40
DateTime::Event::Recurrence 0  0.16
DateTime::Set   0.1401 0.25
Test::More  0  0.70

--
ENVIRONMENT AND OTHER CONTEXT
--

Environment variables:

PATH = 
/usr/local/bin:/usr/X11R6/bin:/usr/X11/bin:/usr/perl5.8.0/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/pilot/bin:/home/cpansand/bin/freebsd6.2:/home/cpansand/bin/sh:/home/cpansand/bin:/usr/X386/bin:/usr/games:/home/cpansand/devel:/mnt/i386/usr/home/e/eserte/work/srezic-misc/scripts
PERL5LIB = 
/usr/local/src/CPAN/build/DateTime-Event-Recurrence-0.16-5MSVql/blib/arch:/usr/local/src/CPAN/build/DateTime-Event-Recurrence-0.16-5MSVql/blib/lib:/usr/local/src/CPAN/build/DateTime-Set-0.25-zPUPYK/blib/arch:/usr/local/src/CPAN/build/DateTime-Set-0.25-zPUPYK/blib/lib:/usr/local/src/CPAN/build/Set-Infinite-0.61-KIBOWw/blib/arch:/usr/local/src/CPAN/build/Set-Infinite-0.61-KIBOWw/blib/lib:/usr/local/src/CPAN/build/YAML-Syck-1.01-nj0BF6/blib/arch:/usr/local/src/CPAN/build/YAML-Syck-1.01-nj0BF6/blib/lib:/usr/local/src/CPAN/build/Audio-SndFile-0.07-itGOJj/blib/arch:/usr/local/src/CPAN/build/Audio-SndFile-0.07-itGOJj/blib/lib:/usr/local/src/CPAN/build/PowerDNS-Backend-MySQL-0.02-QkMQU5/blib/arch:/usr/local/src/CPAN/build/PowerDNS-Backend-MySQL-0.02-QkMQU5/blib/lib:/usr/local/src/CPAN/build/Net-UploadMirror-0.07-D6uHFx/blib/arch:/usr/local/src/CPAN/build/Net-UploadMirror-0.07-D6uHFx/blib/lib:/usr/local/src/CPAN/build/Net-MirrorDir-0.07-nTYU1f/blib/arch:/usr/local/src/CPAN/build/Net-MirrorDir-0.07-nTYU1f/blib/lib:/usr/local/src/CPAN/build/PowerDNS-Control-Client-0.02-KGtIbe/blib

ANNOUNCE DateTime::Incomplete

2008-01-18 Thread Flavio S. Glock
DateTime::Incomplete

0.03  2008-01-18
- updated strftime tests, bug reported by cpan testers.


- Flavio S. Glock


Re: New Module - DateTime::NaturalLanguage

2008-01-11 Thread Flavio S. Glock
2008/1/11, Luke Hutscal [EMAIL PROTECTED]:
 That's a thought - basically all it does is convert integer values to
 phrases - 200  to 3 minutes, 20 seconds, or 3612 to 24 hours, 12
 seconds.

 Seeing as the module doesn't really make sense for inclusion into the
 DateTime::* namespace, does anyone have any recommendations on a better
 namespace to put it in?

There is Lingua::EN::Numbers::Years

How about Lingua::EN::Numbers::Seconds ?

- Flavio S. Glock


ANNOUNCE Date::Tie 0.18

2008-01-10 Thread Flavio S. Glock
Date::Tie 0.18

- fixed week number (http://rt.cpan.org/Ticket/Display.html?id=32071)


This is almost 5 years after version 0.17

- Flavio S. Glock


Re: DateTime::Set from_recurrence problem

2007-11-06 Thread Flavio S. Glock
The code works fine for me on OSX, using the same module versions,
installed from cpan.
Anyway, please check if this fixes the problem: this sets the timezone
on the whole set, instead of the start/end dates.


my $dt1 = DateTime-new(year = 2007, month = 11)-truncate(to = 'month');

my $dt2 = DateTime-new(year = 2007, month = 11, day =
5)-truncate(to = 'day');

my $dtset = DateTime::Set-from_recurrence(
   start = $dt1,
   end = $dt2,
   recurrence = sub {
   return $_[0]-truncate( to = 'day' )-add( days = 1 );
   },
   )-set_time_zone('EST5EDT');


- Flavio S. Glock

2007/11/5, Phil Sorber [EMAIL PROTECTED]:
 I searched around a little bit and it seems that most bug reports for
 DateTime::Set have to do with the from_recurrence method or misunderstandings
 thereof. So it is entirely possible that the problem I am about to describe is
 not a bug but a intricacy of handling Daylight savings in recurrence sets.

 First off I am using the perl-DateTime-0.2901-1.2.el4.rf and
 perl-DateTime-Set-0.25-2.2.el4.rf RPM's from RPMForge. I am running perl 5.8.8
 (perl-5.8.8-4.el4s1) on CentOS 4.5 (Linux hostname.domain.com
 2.6.9-55.0.12.ELsmp #1 SMP Fri Nov 2 11:19:08 EDT 2007 i686 i686 i386 
 GNU/Linux).


 The Code:
 --

 #!/usr/bin/perl

 use strict;
 use warnings;

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

 # The reason for the truncate's is because usually I am not
 # specifying year and month I am simply doing now().

 my $dt1 = DateTime-new(year = 2007, month =
 11)-set_time_zone('EST5EDT')-truncate(to = 'month');

 my $dt2 = DateTime-new(year = 2007, month = 11, day =
 5)-set_time_zone('EST5EDT')-truncate(to = 'day');

 # This was adapted from an example on the DateTime::Set doc page

 my $dtset = DateTime::Set-from_recurrence(
 start = $dt1,
 end = $dt2,
 recurrence = sub {
 return $_[0]-truncate( to = 'day' )-add( days = 1 );
 },
 );

 my $itr1 = $dtset-iterator;

 while (my $dt3 = $itr1-next())
   {
print DateTime::Format::MySQL-format_date($dt3) . \n;
   }

 --

 Output:

 2007-11-01
 2007-11-02
 2007-11-03
 2007-11-04
 2007-11-04
 2007-11-04
 2007-11-04
  etc

 When I run the previous code it iterates as you would expect to '2007-11-04'
 then repeatedly prints out '2007-11-04'. I think this has to do with daylight
 savings time. Nov 4th effectively has 25 hours in it so adding 24 hours (1 
 day)
 will leave you still in Nov 4th. I fixed this by adding hours = 26 instead 
 of
 days = 1 and then doing a truncate( to = 'day' ). I don't really like 
 that,
 but If this is the intended behavior I will live with it.

 Thanks.



Re: Simple math: partitioning the time between two DateTimes

2007-08-08 Thread Flavio S. Glock
2007/8/7, J. David Blackstone [EMAIL PROTECTED]:
   Given two DateTime objects as input, and an integer $N, I want to
 partition the time in between them into $N equal intervals and return
 an array of $N + 1 evenly-spaced DateTimes that begins with the first
 input DateTime and ends with the last input DateTime.

you can hide the complexity with a Set:


  use DateTime::Event::ICal;

  my $start = DateTime-now;
  my $end = DateTime-new( year = 2008, month = 7, day = 12 );
  my $n = 3;

  my $split = DateTime::Event::ICal-recur(
dtstart = $start,
freq = secondly,
interval = int( ($end-hires_epoch() - $start-hires_epoch()) / $n ),
until = $end,
  );
  print join(\n,  @{[ $split-as_list ]} ), \n;


  # you can hide the rounding error by replacing the last value with
$end itself.

  print rounded:\n;
  @values =  @{[ $split-as_list ]};
  $values[-1] = $end;
  print join(\n,  @values ), \n;

- Flavio S. Glock


Re: DateTime::Event again

2007-06-12 Thread Flavio S. Glock

I've got this module DateTime::Event::Spreadsheet in the DateTime
repository (it's not in CPAN):

http://perl-date-time.svn.sourceforge.net/viewvc/perl-date-time/modules/DateTime-Event-Spreadsheet/trunk/README?revision=455view=markup


From the POD:

---

   use DateTime::Event::Spreadsheet;
   use DateTime::Event::Recurrence;
   use DateTime::SpanSet;

   my $dtes = DateTime::Event::Spreadsheet-new;

   # - business hours

   $dtes-set( 'biz-start-set' =
   DateTime::Event::Recurrence-daily(
   hours = 9 ) );

   $dtes-set( 'biz-end-set' =
   DateTime::Event::Recurrence-daily(
   hours = 18 ) );

   # - some holidays

   $dtes-set( 'holiday-new year' =
   DateTime::Event::Recurrence-yearly(
   months = 1, days = 1 ) );

   $dtes-set( 'holiday-labor day' =
   DateTime::Event::Recurrence-yearly(
   months = 5, days = 1 ) );

   $dtes-set( 'holiday-sunday' =
   DateTime::Event::Recurrence-weekly(
   days = 7 ) );

   # - utility functions

   $dtes-set_function( 'holidays-spanset' =
   sub {
   my $ss = shift;
   return DateTime::SpanSet-from_set_and_duration(
   set = $ss-as_set( match = qr/^holiday-/ ),
   days = 1 );
   }
   );

   $dtes-set_function( 'biz-spanset' =
   sub {
   my $ss = shift;
   return DateTime::SpanSet-from_sets(
   start_set = $ss-get( 'biz-start-set' ),
   end_set =   $ss-get( 'biz-end-set' ),
   );
   }
   );

   # - is today a holiday?

   my $is_holiday = $dtes-contains(
   DateTime-today,
   match = qr/^holiday-/ );

   # - what are the business hours for this week?

   my $week_span = DateTime::Span-from_datetimes(
   start =  DateTime-today-truncate( to = 'week' ),
   before = DateTime-today-truncate( to = 'week' )-add( days = 7 ),
   );

   my $biz_hours_week_spanset =
   $week_span -intersection(
   $dtes-get( 'holidays-spanset' ) ) -intersection(
   $dtes-get( 'biz-spanset' ) );

---

I'm not sure if it fits your needs, but I hope it can help as a starting point.

- Flavio S. Glock


2007/6/12, Matthew Persico [EMAIL PROTECTED]:

On 5/16/07, Metz, Bobby [EMAIL PROTECTED] wrote:
 At a high level, recurring and single events don't have to have
 different properties IMO, depending on how you structure the series of
 event references.  If you separate the event information from the
 scheduling, having an array, hash, whatever of scheduled events would
 simply hold references to the event object to access the event details.
 All event objects could have a recurring event property and the
 required extra parameters defining the recurrence.  Any action on an
 object marked as a recurring event would kick off special routines to
 populate the extra event object references in the scheduling list or
 update those references if an event object is changed, deleted, or say
 converted to a standalone event.

 Just my 2 cents,

 Bobby

Bobby brings up a point. If you go back a couple of threads where was
a dissagreement about an event containing the multiple time
information and putting multiple events (or, trivially, one event)
into a list, you can come up with two maps.

Let's look at the latter first

DateTime::Event - who what where added, time inherited from DateTime
DateTime::Schedule contains one or more events.

If you try the former:

DateTime::Event - who what where added, time inherited from DateTime,
list of DateTime added as DateTime::Schedule if a recurrning event

it doens't seem to fit. Heck, it doesn't even READ correctly to me.


 -Original Message-
 From: Dave Rolsky [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, May 16, 2007 2:04 PM
 To: datetime
 Subject: Re: DateTime::Event again

 On Wed, 16 May 2007, Simon Wistow wrote:

  On Wed, May 16, 2007 at 04:46:56PM +0100, Zefram said:
  A recurring event is not a single event.  It is a structured group
 of
  events.  You should have distinct classes for single event and
 recurrence.
  Most of the methods you list are applicable to one class or the
 other,
  not both.
 
  Hmm, I disagree. In every calendaring system I've come across a
  recurring event and a single event are represented as the same thing
  only with different properties. A recurring event is a single entity -
  it is one thing and should only be stored one time.

 I think you're mixing together the end-user view of an event and the
 program API view.

 Clearly, when one is programming a calendar system, recurring and single

 events would have to have some different properties.

  Using your description, a one-off event could be described as a
  structured group containing only one event.

 That's not a bad idea.

 A better distinction might be between a recurring event (every Tuesday
 at
 noon) and a specific instance of that recurring event (May 15 at noon).


 -dave

Fwd: Unauthorized release: DateTime-Cron-Simple

2007-05-07 Thread Flavio S. Glock

(Adriano: I'm forwarding to datetime@perl.org)

-- Forwarded message --
From: Adriano Ferreira [EMAIL PROTECTED]
Date: 07/05/2007 08:19
Subject: Unauthorized release: DateTime-Cron-Simple
To: Module Authors List [EMAIL PROTECTED]


A while back, I wrote a replacement to DateTime::Cron::Simple distribution:

   The original, by Brendan Fagan
   http://search.cpan.org/dist/DateTime-Cron-Simple/

   The new one
   http://search.cpan.org/~ferreira/DateTime-Cron-Simple-0.3/

That rewrite was prompted after a calling by Adam Kennedy:

  Request for Volunteers: DateTime::Cron::Simple Replacement
  http://use.perl.org/~Alias/journal/31155

The issue was that the distribution had no license and contacting the
author for taking care of this was received with silence or with harsh
answers:

   A June 2006 thread
   http://www.nntp.perl.org/group/perl.modules/2006/06/msg49264.html
   A September 2006 thread
   http://www.nntp.perl.org/group/perl.datetime/2006/09/msg6433.html
   More
   http://www.nntp.perl.org/group/perl.modules/2006/09/msg50928.html
   http://www.nntp.perl.org/group/perl.modules/2006/09/msg50939.html

That was briefly discussed in datetime mailing list,

http://www.nntp.perl.org/group/perl.datetime/2006/09/msg6447.html

with some suggestions about the proper name and implementation. It has
to be said that Dave Rolsky disapproves the current namespace (as can
be read in the mentioned thread). The module has at least one
significant user: WebGUI. And so it is important for those who rely on
WebGUI and its dependencies. Even if WebGUI adopted one of the
solutions pointed out at the discussion, the previous versions would
still use DateTime::Cron::Simple.

The main point raised by Adam and shared with me was that an
API-compatible code was needed with a clear license. And that was
which I wrote. However, the distribution stood there at CPAN without
the apropriate permissions, so that Brendan's version is what CPAN
shells see and there were not much opportunities for this code to be
tried.

So I would like to raise the discussion again asking for the right
permissions to make this an authorized released with correct indexing.

Best regards,
Adriano Ferreira


Re: recurring system

2007-03-27 Thread Flavio S. Glock

There are several ways to do this. For example:

use DateTime::Event::Recurrence;
use strict;
my $daily_at_10_30 = DateTime::Event::Recurrence-daily(
 hours = 10,
 minutes = 30);

my $iter = $daily_at_10_30-iterator(
 after = DateTime-new(
year = 2007,
month = 1, day = 15, hour = 11
 ) );

for(my $i = 0; $i  5; $i++)
{
  print $iter-next-datetime . \n;
}



Eventually what I will need to do is compare the -next recurrence with
the current (local) datetime and if the -next is less than that, get
next recurrence.


I think this is:

  $daily_at_10_30-next( $local_time )

- Flavio S. Glock


Re: Bug in recurrences that include March 11?

2007-03-14 Thread Flavio S. Glock

DateTime::Event::Recurrence says:
The start parameter should have no time zone.

I'm not sure what was the reason for that, but you'd better not use a
timezone in $start.
This probably needs to be better documented.

This seems to work:
---
$start = DateTime::Format::ICal-parse_datetime($rfc_time);

# Create a datetime set with a recurrence of daily, starting at the
# datetime we created above.
$set = DateTime::Format::ICal-parse_recurrence(
 dtstart = $start,
 recurrence = 'FREQ=DAILY;INTERVAL=1');
$set-set_time_zone('America/Chicago');
---

- Flavio S. Glock

2007/3/14, Tim Klein [EMAIL PROTECTED]:

Hello, all!

We're seeing what appears to be a Daylight Saving Time related bug.
But maybe instead we're asking DateTime to do something unreasonable?
(I've been following the discussion between Matthew and Zefram, but I
think this is a different issue.)

Below is a small Perl program that demonstrates the problem.  The
program constructs a daily at 23:00 recurrence, and then prints the
first four occurrences in it.  (In case it matters, we're running
this on a Linux machine whose kernel has been updated for the new
Daylight Saving Time change dates in the USA.)

Question #1:  Run the program.  This is the output:

Occurrence #1:  2007-03-10T23:00:00 America/Chicago CST (1173589200)
Occurrence #2:  2007-03-12T23:00:00 America/Chicago CDT (1173758400)
Occurrence #3:  2007-03-13T23:00:00 America/Chicago CDT (1173844800)
Occurrence #4:  2007-03-14T23:00:00 America/Chicago CDT (1173931200)

Why did it skip 2007-03-11?  That was the day when CST became CDT,
but why would that cause it to skip that day altogether?

===

Question #2: In the line near the top that assigns $rfc_time, change
the 23 to some lower number, such as 14.  In other words, change the
start time of the recurrence from 23:00 to 14:00.  Run the program.
This is the output:

Occurrence #1:  2007-03-10T14:00:00 America/Chicago CST (1173556800)
Occurrence #2:  2007-03-11T15:00:00 America/Chicago CDT (1173643200)
Occurrence #3:  2007-03-12T14:00:00 America/Chicago CDT (1173726000)
Occurrence #4:  2007-03-13T14:00:00 America/Chicago CDT (1173812400)

Why does it show a different time on 2007-03-11 than on the other
days?  I think it should say 14:00 CDT, right?  But even if 15:00 is
correct for some reason, then why isn't 15:00 also correct for all of
the days after that?

Thank you for any help!

Tim
Dallas, Texas, USA

==

#!/usr/bin/perl

use DateTime;
use DateTime::Format::ICal;


$rfc_time = '20070310T23';

# Create a start datetime.
$start = DateTime::Format::ICal-parse_datetime($rfc_time);
$start-set_time_zone('America/Chicago');


# Create a datetime set with a recurrence of daily, starting at the
# datetime we created above.
$set = DateTime::Format::ICal-parse_recurrence(
   dtstart = $start,
   recurrence = 'FREQ=DAILY;INTERVAL=1');


# Show the first few occurrences in that datetime set.
for ($i=1; $i = 4; ++$i) {

$occurrence = $set-next;

print Occurrence #$i:  , $occurrence,
   , $occurrence-time_zone-name,
   , $occurrence-time_zone_short_name,
   (, $occurrence-epoch, )\n;

}








Re: A generic 'Event' object

2007-03-01 Thread Flavio S. Glock

There was some discussion on the list about adding info to occurrences.
I only found this thread:
 http://www.nntp.perl.org/group/perl.datetime/2005/07/msg5959.html

At that time I was working on the DateTime::Event::Spreadsheet module
- it never got to CPAN, but you can find it in the DateTime cvs
repository if you are interested.

- Flavio S. Glock

2007/2/23, Simon Wistow [EMAIL PROTECTED]:

Recently I've been thinking about event aggregation from things like
Google Calendar, iCalendar files, National Holiday, Upcoming.org, Palm
Calendar etc etc


There were a bunch of things I learnt from Data::ICal::DateTime and
Net::Google::Calendar to do with stuff like all day events and repeating
events such exploding them within a time range, having a base event
(say a birthday) and then  having instances of that event have extra
information (location of birthday party this year).

It would seem like a good idea to have any Perl module that could deal
with events use a standard ::Event module and, in my mine anway, that
would fit within DateTime's purview.

Thoughts?

Simon


Re: Set::Infinite backtrack too deep from DateTime::Set

2007-02-05 Thread Flavio S. Glock

2007/2/5, Joshua ben Jore [EMAIL PROTECTED]:

I'm using DateTime::Set to encode a radio station's program lineup.
It's about 170 weekly recurrences that are all mostly about an hour
apart.


Set::Infinite can't optimize this query, so it's actually making 170
or more calls to Recurrence and comparing them.

You could get a big optimization by combining several recurrences into
a single set, like:

 my $set = DateTime::Event::Recurrence-weekly(
   days = [ 2, 4 ], hours = [ 10, 14,  -1 ], minutes = [ 15, 30, -15 ]
 );


- Flavio S. Glock


Re: Date Span Formatter

2006-11-25 Thread Flavio S. Glock

2006/11/24, Beaudet, David P. [EMAIL PROTECTED]:

I'm working on an extension to the Bricolage CMS to handle event schedules and 
am specifically looking for a Perl module to create a human readable schedule 
listing from a sequence of date time spans...


DateTime::Format::Natural is the place to implement this, but it isn't
finished yet.

DateTime-Format-ICal provides an ICal text output, which is structured
enough to be parsedformatted into human-readable sentences.

There are some examples of the ICal output here:
 http://search.cpan.org/src/DROLSKY/DateTime-Format-ICal-0.08/t/04recurrence.t

- Flavio S. Glock


Re: Subtracting Weekends and Holidays from a SpanSet

2006-07-11 Thread Flavio S. Glock

11 Jul 2006 06:19:21 -0700, Rick [EMAIL PROTECTED]:

I am working on developing a system that calculates the time worked on
my company's projects.   For each project I have a SpanSet representing
the time reportedly worked on each project  and need to eliminate all
time for weekends and work holidays.

My approach has been to build a spanset for the weekends and holidays
and use the 'complement' function to remove that time from the project.


 $slatime = $project_spanset-complement(
$weekends_and_holidays_spanset );

This works fine, but it is terribly slow on my system.  It takes over
one seconds per project to compute, and we have over 10,000 projects.

Is there a way to speed it up given that we are ONLY working with full
days? (i.e. the weekends and holidays we are trying to subtract are
complete days)


Sets are not easily optimizable, sorry.
You may have to use plain old arrays, pre-calculate the values and use
grep or a for-loop.

OTOH, the grep() method in DateTime::Set may be useful in this case.

   # example: filter out any sundays
   $set = $set2-grep(
   sub {
   return ( $_-day_of_week != 7 );
   }
   );

- Flavio S. Glock


Re: Misc. DT module interactions resulting in an infinite loop?

2006-05-19 Thread Flavio S. Glock

2006/5/18, Jerrad Pierce [EMAIL PROTECTED]:

I've run into an odd issue with DateTime and Memoization (often necessary to
get decent performance for processing 10-20k records with repeat dates). I've
processed a lot of data this way but I recently ran into a few records that
caused an infinite loop, below is some simplified sample code that reproduces
the behavior. It goes away if I don't memoize DT::from_object, but I still
find it odd and thought somebody might be interested in looking into it further
(or documenting the potential for trouble?)


DateTime objects can mutate, and this can potentially
place the memoization buffer in an invalid state, because the internal
data is shared.
One solution could be to deep clone every DT before modification,
but this can be as expensive as not memoizing at all.

- Flavio S. Glock


Re: Scheduling FAQ?

2006-05-16 Thread Flavio S. Glock

2006/5/16, Jerrad Pierce [EMAIL PROTECTED]:

What's the best way to iterate over Mondays, Tuesdays, and Thursdays between
two dates?


For some value of best:

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

my $dt1 = DateTime-today;
my $dt2 = $dt1-clone-add( months = 1 );

print interval: $dt1 $dt2\n;

my $set = DateTime::Event::ICal-recur(
  dtstart = $dt1,
  until   = $dt2,
  freq ='weekly',
  byday = [ 'mo', 'tu', 'th' ],
);

my @days = $set-as_list;
print days as list: @days\n;

print days as iterator: ;
my $iter = $set-iterator;
while ( my $dt = $iter-next ) {
 print ' ', $dt-datetime;
}

---

- Flavio S. Glock


Re: Debugging and DateTime?

2006-04-25 Thread Flavio S. Glock
Would you mind providing a (non)working example?

OTOH, you can specify span durations using full hours (spansets are
created using the 'before' parameter by default):

DateTime::SpanSet-from_set_and_duration(
   set = DateTime::Event::Recurrence-daily( hours = $min),
   hours = 1+$max-$min,
   )-set_time_zone('America/New_York');

- Flavio S. Glock

2006/4/25, Luke Hankins [EMAIL PROTECTED]:
 I'm running into a wall trying to figure out why and intersection of a Span
 and a SpanSet isn't coming out the way I'm expecting and am being stymied
 by the opacity of DateTimes in general.

 In broad terms, I'm doing something like this:

[cut...]

 The spanset and span seem to be what I'm expecting, but the intersection
 keeps coming out as undefined.  What tools exist to help dig into this?



Re: Debugging and DateTime?

2006-04-25 Thread Flavio S. Glock
(forwarding back to the list)

2006/4/25, Luke Hankins [EMAIL PROTECTED]:
 * Flavio S. Glock wrote:
  Would you mind providing a (non)working example?

 Hurm.  The act of distilling it down to an example seems to have gotten it
 working.  Off to dig further. :-)

 This is slightly harder because DateTime::Format::Duration won't install on
 my machine due to test issues.  Is there an easy way to get the length of
 a Duration in seconds without using that module?

The way how to calculate seconds depends a lot on the context where
the result will be used.

One of the possible ways is to not use Duration at all - instead, you
can add a difference to a datetime:

  $dt = $dt + ( $dt_max - $dt_min );

  OTOH, you can specify span durations using full hours (spansets are
  created using the 'before' parameter by default):
 
  DateTime::SpanSet-from_set_and_duration(
 set = DateTime::Event::Recurrence-daily( hours = $min),
 hours = 1+$max-$min,
 )-set_time_zone('America/New_York');

 Ooh, good point.  I wrote that before I understood the difference between
 end and before.

 Thanks!


np.

- Flavio S. Glock


Re: DateTime: gpsweek,gpssecond, fraction_of_day

2005-12-12 Thread Flavio S. Glock
2005/12/8, Renato Serodio [EMAIL PROTECTED]:
 Dear DateTime developers,

 I'm doing some calculations which involve calendrical calculations such
 as are implemented by your module, with additional GPS time calculations.

 To get everything working, I need to use DateTime, DateTime::Duration
 and the Astro::Time and DateTime::Precise modules. Now, these last two
 are in because there's no in-built way to get the fraction of day, nor
 gps week number and seconds after start of week.

 I suppose it would be desirable to have these methods in DateTime. It
 appears there's no module that implements them and plays nice with DateTime.

 Since DateTime::Precise is around for so long, and there was even an
 attempt of the author to get the things integrated, I'd like to ask how
 the matter stands: are there plans to implement this code, are there
 better workarounds, or do you need someone to do it?

 Regards,

 Renato Serodio

DateTime::Precise is based on a different DateTime.pm module than
the DateTime project.
How about migrating this into a DateTime::Calendar::GPS module?

- Flavio S. Glock


Re: moving FAQ to the wiki?

2005-11-23 Thread Flavio S. Glock
2005/11/21, Rick Measham [EMAIL PROTECTED]:

 It's a pity to lose the tests though ..

How about a WWW::Mechanize script that would download the FAQ page and
run tests?

(the script itself would be in a wiki page, such that a volunteer
would easily start/modify it)

- Flavio S. Glock


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

2005-10-05 Thread Flavio S. Glock
2005/10/4, Mark D. Anderson [EMAIL PROTECTED]:
 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:

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

- Flavio S. Glock


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

2005-10-04 Thread Flavio S. Glock
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: request advice on how to debug/fix DateTime-Set-0.23 test failures.

2005-10-04 Thread Flavio S. Glock

David Dyck wrote:


The following test failed
not ok 7 - recurrence with time zone
not ok 10 - recurrence with time zone, arg without time zone
not ok 12 - recurrence with time zone, arg with time zone
not ok 13 - default locale
not ok 14 - new locale


The most common errors reported were on line 338
 count   error message
363_callback_previous: Delta components are: months 0 days 0 
minutes 0 seconds 0 nanoseconds 0
333_callback_previous: iterator can't find a previous value, got 
2001-12-31 after 2001-12-31 at 
/hdd1/jd/usr2/dcd/CPAN/build/DateTime-Set-0.23/blib/lib/DateTime/Set.pm 
line 338.
 10_callback_previous: iterator can't find a previous value, got 
2002-02-01 after 2002-01-01 at 
/hdd1/jd/usr2/dcd/CPAN/build/DateTime-Set-0.23/blib/lib/DateTime/Set.pm 
line 338.
  8_callback_previous: iterator can't find a previous value, got 
2001-12-31 after 2001-12-02 at 
/hdd1/jd/usr2/dcd/CPAN/build/DateTime-Set-0.23/blib/lib/DateTime/Set.pm 
line 338.
  5_callback_previous: iterator can't find a previous value, got 
2002-01-01 after 2001-12-01 at 
/hdd1/jd/usr2/dcd/CPAN/build/DateTime-Set-0.23/blib/lib/DateTime/Set.pm 
line 338.
  5_callback_previous: iterator can't find a previous value, got 
2001-12-01 after 2001-11-22 at 
/hdd1/jd/usr2/dcd/CPAN/build/DateTime-Set-0.23/blib/lib/DateTime/Set.pm 
line 338.
  2_callback_previous: iterator can't find a previous value, got 
2001-12-02 after 2001-11-21 at 
/hdd1/jd/usr2/dcd/CPAN/build/DateTime-Set-0.23/blib/lib/DateTime/Set.pm 
line 338.


if I ignore error messages with '_callback_previous:'
 the failures were:

1..14
not ok 7 - recurrence with time zone
#   Failed test 'recurrence with time zone'
#   in t/15time_zone.t at line 60.
#  got: '2001-12-02T00:00:00 Asia/Taipei'
# expected: '2001-12-01T00:00:00 Asia/Taipei'
not ok 10 - recurrence with time zone, arg without time zone
#   Failed test 'recurrence with time zone, arg without time zone'
#   in t/15time_zone.t at line 87.
#  got: '2001-12-02T00:00:00 Asia/Taipei'
# expected: '2001-12-01T00:00:00 Asia/Taipei'
not ok 12 - recurrence with time zone, arg with time zone
#   Failed test 'recurrence with time zone, arg with time zone'
#   in t/15time_zone.t at line 102.
#  got: '2001-12-01T14:00:00 America/Sao_Paulo'
# expected: '2001-11-30T14:00:00 America/Sao_Paulo'
not ok 13 - default locale
#   Failed test 'default locale'
#   in t/15time_zone.t at line 119.
#  got: 'Mon'
# expected: 'Sun'
not ok 14 - new locale
#   Failed test 'new locale'
#   in t/15time_zone.t at line 124.
#  got: 'Mon'
# expected: 'Sun'
# Looks like you failed 5 tests of 14.



Any ideas on where I should look?
  David




David:

Thank you for offering to help!

Those tests failures are related to a change in the way the DateTime.pm 
module deals with add/subtract in objects that have timezones.


We have been discussing how to fix this for a while, in the DateTime 
list (would you like to join in?  - see: 
http://datetime.perl.org/mailing_list.html )


On the other hand, these failures only happen in these tests - no other 
DateTime::Set derived modules seem to be affected. Maybe the tests 
should simply be skipped?


In any case, the error is caused by the calculation in DateTime::Set 
line 325 - the calculated offset doesn't work near DST changes, because 
(t/15time_zone.t line 49):


 $_[0]-truncate( to = 'month' )-add( months = 1 );

instead of returning next month, it returns the same month/day ???
More specifically, adding 1 month to 2001-10-01T00:00:00 yields 
2001-10-31T00:00:00 - which is the same month.


In short, the test can be fixed, but the error is actually in the way 
the timezone math is done, or I'm misinterpreting the DateTime.pm math 
(which is quite possible)


Thank you.

(cc'ing the DateTime list)

- Flavio


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

2005-10-03 Thread Flavio S. Glock
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 Flavio S. Glock
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?

 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).

- Flavio S. Glock


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

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

- Flavio S. Glock

2005/9/23, Mark D. Anderson [EMAIL PROTECTED]:
 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.



Re: ICal recurrence help wanted

2005-09-05 Thread Flavio S. Glock
This may be a bug - I think byday=[mo] causes hour/min/second to be zero.
I'll test this.

- Flavio S. Glock

2005/9/5, Chiradeep Chhaya [EMAIL PROTECTED]:
 Hi
 
 I am using the DateTime::Event::ICal-recur() function to calculate
 recurrences and whether the rpesent date/time lies in the recurrence.
 
 To state simply, my start and end dates as well as the recurrence are
 declared as follows:
 
 my $dt = DateTime-new( year   = 2005,
   month  = '08',
   day= 29,
  hour= 15,
  minute  = 05,
  second  = 00
 );
 my $end = DateTime-new( year = 2005,
   month = 11,
   day= 27,
  hour= 16,
  minute  = 25,
  second  = 00
  );
 my $set = DateTime::Event::ICal-recur(
dtstart = $dt,
freq ='secondly',
  interval = 1,
  byday = [mo],
  dtend   = $end
 
 );
 
 And this is what I need to check
 my $bool = $set-contains( DateTime-now() );
 
 As of this writing, DateTime-now() returns 20050905T162355 in the
 ICal format and the day is Monday.
 
 I have two questions to ask here:
 1) The bool value returned is FALSE whereas I believe it should be true.
 2) Without the byday and interval arguments, the bool value is TRUE.
 Are these arguments causing issues?
 
 Appreciate any help in this regard.
 
 Many thanks
 
 -Chiradeep



Re: [RFC] Data::ICal::DateTime

2005-08-11 Thread Flavio S. Glock
 On Wed, Aug 10, 2005 at 06:38:32PM -0300, Flavio S. Glock said:
  The internal processing sequence should be changed to (pseudo code):
 
$tz = $dtstart-tz
$dtstart = $dtstart-floating
return $recurr( $dtstart )-set_timezone( $tz )

 Ok, that works fine as long as I don't set the timezone on the $recur
 which gets me, err, no results whatsoever - whether I set the TZ on the
 span or not.

(You are right - I tried it and it didn't work)

I sent a fix to the datetime repository as DateTime::Event::Recurrence 0.17
Please let me know if it works.

- Flavio S. Glock


Re: [RFC] Data::ICal::DateTime

2005-08-10 Thread Flavio S. Glock
Yes, I think it is a bug - RFC2445 shows some examples when DTSTART
has a timezone:

  DTSTART;TZID=US-Eastern:19970902T09
  RRULE:FREQ=DAILY;COUNT=10

The internal processing sequence should be changed to (pseudo code):

  $tz = $dtstart-tz
  $dtstart = $dtstart-floating
  return $recurr( $dtstart )-set_timezone( $tz )

- Flavio S. Glock


add(months) bug in DateTime-0.2901?

2005-08-10 Thread Flavio S. Glock
I'm debugging a new failure in DateTime::Set t/15time_zone.t.
It fails with an infinite loop in this recurrence:

  my $months = DateTime::Set-from_recurrence(
 recurrence = sub {
$_[0]-truncate( to = 'month' )-add( months = 1 );
 }
 )
 -set_time_zone( 'Asia/Taipei' );

After adding the following debugging code:

  my $dt = $_[0]-clone;
  print $dt-datetime,'T',$dt-hms,\n;
  $dt-truncate( to = 'month' );
  print $dt-datetime,'T',$dt-hms,\n;
  $dt-add(months=1);
  print $dt-datetime,'T',$dt-hms,\n;
  print \n;

I got:

  2001-11-22T00:00:00T00:00:00
  2001-11-01T00:00:00T00:00:00
  2001-12-02T00:00:00T00:00:00

  2001-12-02T00:00:00T00:00:00
  2001-12-01T00:00:00T00:00:00
  2001-12-31T00:00:00T00:00:00

2001-12-01 + 1 month = 2001-12-31

- Flavio S. Glock


Re: Store DateTime::Event::Cron objects ?

2005-08-08 Thread Flavio S. Glock
2005/8/8, Matt Sisk [EMAIL PROTECTED]:
 Quoting Kaare Rasmussen [EMAIL PROTECTED]:
  The same question goes for DateTime::Set objects. Can they be made
  persistent?
 
 Flavio was working on something along these lines

It actually worked, but the performance was too bad for complex sets.
The database was not able to optimize the queries, and the execution
time grew exponentially.

I think the solution for storing in a database still is to iterate the
set and store the dates.

The best alternative would be to use a calendar server.

About making the recurrences persistent - DateTime::Event::ICal can
stringify and instantiate back most recurrences generated with
DateTime::Event::Recurrence and DateTime::Event::ICal.

- Flavio S. Glock


Re: Business days in a DateTime module

2005-07-25 Thread Flavio S. Glock
I think the consensus here was that this kind of application would be
better handled by a database.

I started an experimental module called DateTime::Event::Spreadsheet,
that can be used to mix recurrences and databases - it should be able
to handle this type of queries, if properly configured. You can get it
from the project CVS.

I did some experiments with storing recurrence rules in a database,
but it ended up being too slow to be useful.

- Flavio S. Glock

2005/7/25, IvorW [EMAIL PROTECTED]:
 Folks,
 
 Does anybody know of a DateTime module that can handle public holidays and 
 business days?
 
 e.g. queries like this:
 
 The number of working days in August 2005.
 
 Adjust $date to the next working day. (This will take account of weekends as 
 well as public holidays)
 
 Is 17th April 2006 a holiday in the current calendar?
 Is 17th April 2006 a holiday in Toronto (a different calendar)?
 
 I need this functionality, and I am considering writing a module for it if 
 none already exists.
 
 Ivor.



Re: Business days in a DateTime module

2005-07-25 Thread Flavio S. Glock
2005/7/25, IvorW [EMAIL PROTECTED]:
 
  From: Flavio S. Glock
  I think the consensus here was that this kind of application would be
  better handled by a database.
 
 Are you talking about doing all the work inside a stored proc?

I mean just a simple table, and some Perl code to initialize it. This
can be very efficient.
 
 I do have a database with the financial centre holiday calendars in it, and I 
 have Class::DBI code hooking to it quite satisfactorily. In my case, I'd 
 prefer to do the work in perl.
 
 
  I started an experimental module called DateTime::Event::Spreadsheet,
  that can be used to mix recurrences and databases - it should be able
  to handle this type of queries, if properly configured. You can get it
  from the project CVS.
 
 Can you explain what you mean by a recurrence.

A recurrence is a rule that you can use to calculate a set of dates
- such as second sunday of may. See the module
DateTime::Event::ICal in CPAN:

  http://search.cpan.org/search?query=datetime-rfc2445

 I presume you didn't upload to CPAN. How do I get to the CVS?

module directory:
http://cvs.sourceforge.net/viewcvs.py/perl-date-time/modules/DateTime-Event-Spreadsheet

module source:
http://cvs.sourceforge.net/viewcvs.py/*checkout*/perl-date-time/modules/DateTime-Event-Spreadsheet/lib/DateTime/Event/Spreadsheet.pm
-
=head1 NAME

DateTime::Event::Spreadsheet - A collection of named DateTime events

=head1 SYNOPSIS

  use DateTime::Event::Spreadsheet;

  $dtes = DateTime::Event::Spreadsheet-new;

  $dtes-set( 
  birthday = DateTime-new( year = 1964 ) 
  );
  print $dtes-get( 'birthday' )-datetime;

  $dtes-set_function( 
  now = sub { DateTime-now } 
  );
  print $dtes-get( 'now' )-datetime;

=head1 DESCRIPTION

DateTime::Event::Spreadsheet is a class for representing 
a collection of DateTime events and the relations between them.

For example, a Spreadsheet could be used to store business
hours information, together with rules for holidays. 
-

 
 
  I did some experiments with storing recurrence rules in a database,
  but it ended up being too slow to be useful.
 
 In my case, I have an existing application and database.

I think the best approach to this problem would be to set up a
calendar server,
which is a specialized database. There are many options in the
internet - Hula, Sun Calendar Server (Netscape's), Plone, and some
more. I'm not familiar with any of these.
You can probably build your own using the DateTime::Event::* modules.

- Flavio S. Glock


Re: porting DateTime to Perl6

2005-07-22 Thread Flavio S. Glock
Dave has started DateTime, and I'm working on Pugs modules
DateTime::Span, DateTime::SpanSet and a new module called
DateTime::Recurrence, as well as the base modules Span, Recurrence,
and Set-Infinite. Everything is under the /ext directory.

I'm splitting the modules into a functional implementation class and
a OO api class.
I found this separation useful when writing tests and optimizing. The
functional base objects can be memoized if desired, and it allows to
have multiple implementations under the same api.

- Flavio S. Glock

2005/7/22, Joshua Hoblitt [EMAIL PROTECTED]:
 Hi Folks,
 
 It appears as if Pugs is very close to being able to host a major
 framework like DateTime.  I think that it's 'time' to start considering
 porting DateTime to Perl6.  Even if for no other reason then to help
 debug Pugs.  The big question that I believe needs to be settled is do
 we make a 'straight' port of DateTime to Perl6 or do we take the
 opportunity to do some re-engineering?
 
 My opinion: While there are several things in DateTime's
 API/implementation that I'd like to see reworked I'm fearful of falling
 prey to Second System Syndrome.  I also feel like DateTime hasn't been
 around long enough to have felt out all the issue's that could/should be
 addressed in an API change.  My proposal is that the initial port be a
 straight across translation of DateTime to Perl6 and that serious
 re-engineering work be put off for DateTime2.
 
 Thoughts? Comments?


Re: DateTime.pm on a Diet

2005-07-06 Thread Flavio S. Glock
I've used this approach in Date::Set. It runs the same test suite of
DateTime::Event::ICal, in one third of the time.

- Flavio S. Glock

2005/7/6, Rick Measham [EMAIL PROTECTED]:
 
 DateTime::Diet (attached) is a simple wrapper around DateTime that
 handles simple new(), set() and get methods. If you ask it for something
 it can't handle by itself, it reblesses your object into full DateTime
 and then calls the method on the DateTime object.


Set::Infinite and DateTime::Set for Perl 6

2005-07-06 Thread Flavio S. Glock
This is the beginning of the Set::Infinite and DateTime::Set packages
for Perl 6. There is not much written yet.

Set::Infinite will probably be split in 3 classes, mirroring the
DateTime::Set package structure:

- Set::Span / DateTime::Span - a single span

- Set::Recurrence / DateTime::Set - recurrences, ordered sets

- Set::Infinite / DateTime::SpanSet - everything else - span
recurrences, multiple spans

Flavio S. Glock


Set-Infinite-0.01.tar.gz
Description: GNU Zip compressed data


DateTime-Set-0.01.tar.gz
Description: GNU Zip compressed data


Re: Fw: Request for clarification

2005-06-16 Thread Flavio S. Glock

Rui Fernandes wrote:
 Forgive my honesty, but this mail list looks kind of dead...Well,
 regarding my previous doubts, only the fourth remains - the others I
 already figure them out.

bless( $hashref, $class ) is as a very low-level object constructor.

This code is creating a DT::TZ::OlsonDB::Observance object, which 
contains the following private fields:


my $last_observance = bless( {
  'format' = 'WE%sT',
  'gmtoff' = '0:00',
  'local_start_datetime' = $dt,
  'offset_from_std' = 0,
  'offset_from_utc' = 0,
  'until' = [],
  'utc_start_datetime' = $dt,
}, 'DateTime::TimeZone::OlsonDB::Observance' )
;

- Flavio S. Glock


Re: Rethinking date math, time zones, etc for Perl 6 (and maybe DateTime2?)

2005-06-15 Thread Flavio S. Glock

John Peacock wrote:
and at any point in that sequence, allow the user to set the value to 
undef (for I don't have any information about anything below this). 
All math operations would then stop at the point where either term (for 
binary operations) contained an undef (hence two disimilarly accurate DT 
objects would have a result no more accurate than the least accurate 
term).  This would allow reduced precision date math to happen naturally.


DateTime::Incomplete
http://search.cpan.org/dist/DateTime-Incomplete/lib/DateTime/Incomplete.pm

It doesn't handle the add methods, but it could do it.
I don't know if it would handle DST correctly. How about writing a test?

- Flavio S. Glock


Re: Storing recurrences in a SQL DBMS?

2005-05-06 Thread Flavio S. Glock
Simon Perreault wrote:
That would create N views (not counting the sub-views). 
It doesn't create temporary tables anymore:
  my $set = DateTime::Event::Recurrence-monthly(
days = [ 10, 20 ], hours = 7 )-
 union(
DateTime::Event::Recurrence-monthly(
days = [ 9 ], hours = 8 ) );
generates:
  CREATE VIEW SET ( N ) AS
(
SELECT ( N + INTERVAL '7 HOUR' ) FROM (
SELECT ( N + INTERVAL '10 DAY' ) FROM MONTHS UNION
SELECT ( N + INTERVAL '20 DAY' ) FROM MONTHS
)
)
  UNION (
SELECT ( N + INTERVAL '8 HOUR' ) FROM (
SELECT ( N + INTERVAL '9 DAY' ) FROM MONTHS
)
)
  ;
This SQL fails with subquery in FROM must have an alias, but that's 
fixable.

- Flavio S. Glock


Re: Storing recurrences in a SQL DBMS?

2005-05-05 Thread Flavio S. Glock
Simon Perreault wrote:
On Thursday 05 May 2005 13:31, Flavio S. Glock wrote:
Flavio S. Glock wrote:
I'm working on a module that translates datetime sets into SQL
statements.

Can you explain how you can serialize infinite sets? 

$ perl -Ilib -MDateTime::Format::SQL -e ' print 
DateTime::Format::SQL-format_set( set = 
DateTime::Event::Recurrence-yearly( months = 7, days = 5 ), 
table_name = 'MY_RECURRENCE', lazy = 1 ) '

Yields (this still needs some optimization):
CREATE VIEW MY_RECURRENCE_28403 ( N ) AS
SELECT ( N + INTERVAL '7 MONTH' ) FROM DT_YEAR;
CREATE VIEW MY_RECURRENCE_83554 ( N ) AS
SELECT ( N + INTERVAL '5 DAY' ) FROM MY_RECURRENCE_28403;
CREATE VIEW MY_RECURRENCE ( N ) AS
SELECT ( N ) FROM MY_RECURRENCE_83554;
You are responsible for maintaining the DT_YEAR table - it may be as 
big as needed.

 Is it possible to do a
 query such as which sets intersect with today? on the SQL
 data resulting from that serialization?
Yes, this is just a normal table.
- Flavio S. Glock


Re: Storing recurrences in a SQL DBMS?

2005-05-05 Thread Flavio S. Glock
Simon Perreault wrote:
which views contain a row that intersects with today? 
You could use a structure like:
create view year_month as
  select n, 'dt_year'  as tbl_name  from dt_year   union
  select n, 'dt_month' as tbl_name  from dt_month;
  n  | tbl_name
-+--
 1970-01-01 00:00:00 | dt_month
 1970-01-01 00:00:00 | dt_year
 1970-02-01 00:00:00 | dt_month
 1970-03-01 00:00:00 | dt_month
 1970-04-01 00:00:00 | dt_month
...
However, I don't know if you can modify a view to add or remove 
recurrences (is it possible?).

Here's my way of doing it. 
I guess I agree with you:
http://www.nntp.perl.org/group/perl.datetime/5749
- Flavio S. Glock


Re: Storing recurrences in a SQL DBMS?

2005-05-04 Thread Flavio S. Glock
I'm working on a module that translates datetime sets into SQL statements.
I'd appreciate to have your feedback on it.
-
NAME - DateTime::Format::SQL
SINOPSIS
my $formatter = DateTime::Format::SQL-factory;
print $formatter-create_table(
set = $set,
table_name = 'MY_RECURRENCE',
)-dump_sql;
METHODS
* factory
Creates a SQL formatter object.
my $formatter =
DateTime::Format::SQL-factory (
format_datetime = sub {
DateTime::Format::MySQL-format_datetime($_[0])
},
global_tables = {
yearly =  'DT_YEARS',
monthly = 'DT_MONTHS',
},
);
The optional parameters are:
- format_datetime
A reference to a function that stringifies datetime objects.
- global_tables
A list of tables that already exist in the database. The new tables will 
be based on existing tables, whenever possible.

- start, end
Define a limiting span for tables.
The methods in the formatter object are:
* create_table
$formatter-create_table (
set = $set,
table_name = 'MY_RECURRENCE',
lazy = 1,
);
If the optional lazy parameter is true, the program will try to create 
a space-efficient VIEW instead of a static TABLE.
Views are automatically expanded when the base tables are updated.
Tables use less run-time CPU, but they take more storage space.

The method can also take optional format_datetime, start and end 
parameters.

* get_sql
Iterates through the internal syntax tree, returning a SQL string at a time.
* dump_sql
Returns the SQL output as a single, possibly large, string.
-
- Flavio S. Glock


Re: Storing recurrences in a SQL DBMS?

2005-05-04 Thread Flavio S. Glock
Flavio S. Glock wrote:
I'm working on a module that translates datetime sets into SQL statements.
I'd appreciate to have your feedback on it.
-
NAME - DateTime::Format::SQL
SINOPSIS
s/SINOPSIS/SYNOPSIS/


Re: Storing recurrences in a SQL DBMS?

2005-05-04 Thread Flavio S. Glock
Flavio S. Glock wrote:
I'm working on a module that translates datetime sets into SQL 
statements.
I'd appreciate to have your feedback on it.
Here is a preliminary version:
http://www.ipct.pucrs.br/flavio/perl/DateTime-Format-SQL-0.00_07.tar.gz
This is the example in the synopsis:
  use DateTime::Format::SQL;
  use DateTime::Event::Recurrence;
  my $set = DateTime::Event::Recurrence-monthly;
  my $formatter = DateTime::Format::SQL-factory;
  print $formatter-format_set( set = $set,
table_name = 'MY_RECURRENCE',
lazy = 1 );
- Flavio S. Glock


Re: Storing recurrences in a SQL DBMS?

2005-05-03 Thread Flavio S. Glock
How about using a view to create a lazy sql recurrence.
For example:
  FREQ=YEARLY;BYMONTH=3,6
--- postgresql ---
CREATE TABLE YEARS ( N DATE UNIQUE PRIMARY KEY );
insert into years values ( date('1990-01-01') );
insert into years values ( date('1991-01-01') );
insert into years values ( date('1992-01-01') );
CREATE VIEW RECURR AS
select ( n + interval '2 month' ) from years union
select ( n + interval '5 month' ) from years;

The sql statements could be generated automatically using a 
DateTime::Format module.

- Flavio


Re: Storing recurrences in a SQL DBMS?

2005-04-29 Thread Flavio S. Glock
Dave Rolsky wrote:
Has anyone done any work on this?
Basically, I'd like to be able to store these in a way that makes 
queries like all the entries for a given month reasonably efficient.

[...]
What I'd really like to see is some way to query both single events and 
recurring events within a given timeframe, all in one query that returns 
a sorted array of occurrences.

Build one table for each data type:
  RECURRENCES - populated with ICal strings
  DATES - populated with SQL native datetimes
  SPANS - populated with SQL native datetime spans
- Slurp all RECURRENCES using DT::Format::ICal; query the recurrences 
using Perl.
- Query DATES and SPANS using SQL.

DateTime::Event::Spreadsheet (still experimental) could be used to 
aggregate all these into a single object.

- Flavio S. Glock


Re: Website FAQ - Calculating TimeSheets

2005-04-20 Thread Flavio S. Glock
Rick Measham wrote:
I'm submitting this as a solution for the FAQ. Anyone who wants to make 
it more elegant is quite welcome! The question came up recently in an 
IRC channel.

Q. How do I work out how many hours have been worked from a timesheet?
This solution takes a file in the format
ISO-Date, WhiteSpace, Name
It does not take into account people who forget to log in or out apart 
from making sure there's an even number of dates for each user.

[Note: this later could be partly solved by splitting into days and then 
checking for an even number of times. Flagging days for which data was 
not calculable]

I changed the date format to ICal. Unfortunately, the durations are now 
printed as seconds.
I turned off warnings because it was complaining that $a and $b were 
used only once.

-
#!/usr/bin/perl
use strict;
use DateTime::Format::ICal;
use List::Util qw(reduce);
my %users;
my $ical = 'DateTime::Format::ICal';
while (DATA)
{
chomp;
my ($dt, $user) = split(/\s/,$_,2);
push( @{$users{$user}}, $dt ) if $dt  $user;
}
for my $user ( keys %users )
{
my @duration;
my @dt = @{$users{$user}};
push @duration,
$ical-parse_period( shift(@dt) . / . shift(@dt) )-duration
while scalar @dt;
print $ical-format_duration( reduce { $a + $b } @duration ),
 $_\n
}
__DATA__
20050101T085500 Mr Coffee
20050101T085800 BigLug
20050101T120100 BigLug
20050101T130100 BigLug
20050101T172300 Mr Coffee
20050101T172600 BigLug


Re: Website FAQ - Calculating TimeSheets

2005-04-20 Thread Flavio S. Glock
Flavio S. Glock wrote:
   print $ical-format_duration( reduce { $a + $b } @duration ),
$_\n
This line should be:
 print $ical-format_duration( reduce { $a + $b } @duration ),
  $user\n
- Flavio S. Glock


Re: DateTime-0.22 compile problems on RH ES 3.0

2004-10-05 Thread Flavio S. Glock
greg fenton wrote:
 
 I'm trying to install DateTime on a new RH ES 3.0 box with
 perl-5.8.0-88.7 (RH RPM)
[...] 
  Testing if you have a C compiler
  Makefile:98: *** missing separator.  Stop.
[...]
 
 Any ideas as to what to look for?

Here -
http://www.nntp.perl.org/group/perl.datetime/5436
 This is a known problem and has been discussed previously on this 
 list. It's perl 5.8.0's attempt at utf8 coninciding with RH making 
 utf8 standard. The two clash and you'll get errors.
 
 There are several solutions:
 1. Upgrade perl
 2. Upgrade RedHat to Fedora (It comes with a newer perl), or
 3. Install like so:
   LANG=
   export LANG
   perl Makefile.PL
   make
   make test
   make install
 That will get rid of RedHat trying to be utf8. You'll continue to have
 problems though. I'd really look at upgrading (or at least setting the
 LANG permanently to somthing non unicode.
 
 Cheers!
 Rick Measham


- Flavio S. Glock


DateTime::Set set_time_zone fix

2004-07-01 Thread Flavio S. Glock
Thanks to Tim Mueller-Seydlitz and Matt Sisk, who found 
a couple of bugs in the DateTime::Set time zone handling. 

I'd like to have some feedback from you, before I put 
the fixed version on CPAN.

You can get the new version from CVS, or send me a mail
and I'll send you a tar file.

You'll need to update Set::Infinite to version 0.59,
it is also in CVS.

These are the changes from DateTime::Set version 0.15:

- fixed time zone handling in the methods:
  set_time_zone
  next/previous/closest/current

- removed limitation of duration size in methods:
  add/add_duration
  subtract/subtract_duration

- requires Set::Infinite 0.59 - uses iterate() experimental
  argument backtrack_callback

- the following methods are now mutators:
  set_time_zone( $tz )
  set( locale = $locale )
  add( unit = $n )
  add_duration( $dur )
  subtract( unit = $n )
  subtract_duration( $dur )

- fixed max/min of an infinite SpanSet
- added test for infinite duration

- from_recurrence() code cleanup

- parameter checking: The 'dates' argument to from_datetimes()
  must be a list of DateTime objects

That's all for now.

- Flavio S. Glock


Re: DateTime::Set set_time_zone fix

2004-07-01 Thread Flavio S. Glock
I'm doing some tests with the revised version of DateTime::Set:

[EMAIL PROTECTED] wrote:
 
 use DateTime::Event::Cron;
 
 $cron = DateTime::Event::Cron-from_cron(cron = ' 15 18 * * 1-5');
 $new_cron = $cron-clone()-set_time_zone('Europe/Berlin');
 
 $date = DateTime-new( year = 2004, month = 6, day = 30,
hour = 17,   minute= 10,
time_zone = 'Europe/London');
 
 print $date-strftime(%a %F %T %Z\n);
# Wed 2004-06-30 17:10:00 GMT/BST

ok

 $date = $date-clone()-set_time_zone('Europe/London');
 
 print $date-strftime(%a %F %T %Z\n);
# Wed 2004-06-30 17:10:00 GMT/BST

ok

 $next = $new_cron-next($date);
 print $next-strftime(%a %F %T %Z\n);
# was: Wed 2004-06-30 19:15:00 CEST

I got Wed 2004-06-30 17:15:00 GMT/BST, it looks correct now.
This is the local London time, when cron ticks 18:15 in Berlin.

 # Let's repeat the same operation as before
 
 $date = DateTime-new( year = 2004, month = 6, day = 30,
hour = 17,   minute= 10,
time_zone = 'Europe/London');
 
 print $date-strftime(%a %F %T %Z\n);
# Wed 2004-06-30 17:10:00 GMT/BST

ok

 $date = $date-clone()-set_time_zone('Europe/Berlin');
 print $date-strftime(%a %F %T %Z\n);
# Wed 2004-06-30 18:10:00 CEST

ok

 $next = $new_cron-next($date);
 print $next-strftime(%a %F %T %Z\n);
# Wed 2004-06-30 18:15:00 CEST

ok.
This is the local Berlin time, when cron ticks 18:15 in Berlin.
It is the same time as before, but in a different time zone.

- Flavio S. Glock


Re: Cron with TimeZone

2004-06-30 Thread Flavio S. Glock
[EMAIL PROTECTED] wrote:
 When I request the next scheduled event I expect always to obtain the same
 instant time, possibly expressed in different time zone. Unfortunately I get
 19:15 CEST and 18:15 CEST. Where am I getting it wrong?

When you ask for 

(1)  cron-set_time_zone( tz )-next( x )

it executes internally as

(2)  cron-next( x )-set_time_zone( tz )

Your way would be:

(3)  cron-next( x-clone-set_time_zone( tz ) )-
(4)set_time_zone( x-time_zone )

Which looks like the best way to do it.
I'm not so sure about like (4), but it looks right.

Do all this agree with what you got?

- Flavio S. Glock


Re: Cron with TimeZone

2004-06-30 Thread Flavio S. Glock
Matt Sisk wrote:
 
 My understanding with the current behavior is that if you set the
 time_zone for the set, that time zone will override the time zone of a
 datetime argument. 

Besides, the time zone is being applied in the wrong order. 
This should be fixed.

The current implementation only works properly when:

- the argument to next() is a floating time zone, or
- there is no backtracking involved (the set is not infinite)

 (since, as was previously discussed, it is
 actually a factory method rather than a mutator)

But this is not the reason why it doesn't work.
There is no code in place to do the proper backtracking of the 
set_time_zone operation. And this is actually a bit complex to write.

 Instead, just rely on
 setting the time zone of the original datetime. 

I agree.

As for the factory vs. mutator, would anyone give a final word on 
whether this should be changed?

The following DateTime::Set methods could be mutators:

  set_time_zone
  set( locale = ... )
  add_duration
  add( years = ... )
  subtract_duration
  subtract( years = ... )

- Flavio S. Glock


Re: Cron with TimeZone

2004-06-24 Thread Flavio S. Glock
Matt Sisk wrote:
 
 Just to be clear, this is the native behavior of DateTime::Set, rather
 than something that DateTime::Event::Cron is introducing into the sets
 it generates. Using your same example, but replacing the cron set with
 an actual (monthly) recurrence set, we see the same behavior:
 

That's right - the problem is that the default timezone for
now() is UTC, even if my TZ is set to another timezone...

  $now = DateTime-now();
  print $now-strftime( %a %F %T %Z\n);
  print $ENV{TZ},\n;
  # Thu 2004-06-24 12:54:49 UTC
  # America/Sao_Paulo

- Flavio S. Glock


  1   2   3   >