ANNOUNCE: DateTime-Calendar-Hebrew-0.04

2003-10-02 Thread Steven J. Weinberger
.04  Thu Oct 03 12:00:00 2003
- moved sunset.pl to eg/sunset.pl. Added more samples.
- added to the docs to explain more about the sunset calculations.
- ran podchecker on my module
Should have all been included in version .03

Steve



Re: ANNOUNCE: DateTime-Calendar-Hebrew-0.02

2003-10-02 Thread Steven J. Weinberger
Flavio,
Your code overcomes the problem that Dave pointed out (the $dt needs to be cloned & truncated before being passed to $sunset) in a different 
fashion - another nice way of doing it.

I see what you're saying about the wrong date - but it's just a matter of perspective. I had to pick which conversion was more important. 
Here's the output of the included eg/sunset.pl (version .04, about to go to PAUSE):

> 2003-09-26T22:30:00 (RD731484) -> 5763-06-29T22:30:00
> 2003-09-26T22:30:00 (RD731484) -> 5764-07-01T22:30:00
in the Gregorian -> Hebrew conversion above, Friday 2003/9/26 is used. Rosh HaShana started at about 7pm, so when I add the sunset feature 
(second line) it says that 10:30pm on friday the 26th is Tishrei 1st, 5764.

> 5763-06-29T22:30:00 (RD731484) -> 2003-09-26T22:30:00
> 5764-07-01T22:30:00 (RD731484) -> 2003-09-26T22:30:00
> 5764-07-15T22:30:00 (RD731498) -> 2003-10-10T22:30:00
Now we convert in the other direction. As you said, in the Hebrew -> Gregorian conversions adding the sunset feature makes the Hebrew day 
jump ahead - but that's what I want. Elul 29th (06/29) at 10:30 pm is really on the night before, and should be 2003/09/25. I take for 
granted that more people need to convert an english date to a Hebrew one. I'm not aware of people using the Hebrew Calendar in daily life - 
only in religious matters. Since the sunset feature is still in effect, setting the Hebrew day to the 14th (last line), has it turning into 
the 15th. If I use your code, then the English to Hebrew conversions don't come out as I want.

I always thought that Date & Time should be more separate when thinking about the Hebrew Calendar. When discussing times in my Shul, we 
always mention an english date and time to represent the Hebrew Date. Conceptually, the time was always 'connected' to the english date.

Just wait until I start calculating prayer times - we'll have a good long debate then :)

Steve

Flavio S. Glock wrote:
This is my version:

[...]
if( $self->{sunset} && $self->{time_zone} ) 
{
my $dt = DateTime->from_object( object => $self );
my $sunset = $self->{sunset}->next( $dt );
$sunset->set_time_zone( $self->{time_zone} );
if ( $sunset->day != $dt->day ) {
$self->{rd_days}--;
}
}

Here is a test:

  use strict;
  use DateTime::Calendar::Hebrew;
  use DateTime::Event::Sunrise;
  my $sunset = DateTime::Event::Sunrise->sunset (
# Latitude/Longitude for NYC
longitude =>'-73.59',
latitude =>'40.38',
  );
  my $h = DateTime::Calendar::Hebrew->new(
  year => 5000, month => 5, day => 15,
  sunset => $sunset,
  time_zone => 'America/New_York' );
  print $h->datetime, " ", ($h->utc_rd_values)[0],"\n";
  $h->set( hour => 22 );
  print $h->datetime, " ", ($h->utc_rd_values)[0],"\n";
  $h->set( day => 18 );
  print $h->datetime, " ", ($h->utc_rd_values)[0],"\n";
  # 5000-05-15T00:00:00 452759
  # 5000-05-15T22:00:00 452758
  # 5000-05-18T22:00:00 452761
- Flavio S. Glock




Re: RFC: API for DateTime::Business:Week

2003-10-02 Thread Flavio S. Glock
Rick Measham wrote:
> 
> $working_hours = new DateTime::Business::Week(
> days  => [1 .. 5],
> start => {hour => 9,  minute => 0},
> end   => {hour => 17, minute => 30}
> );
> 
> and, for those with more complex weeks:
[...]

See also:

  DateTime::Format::ICal -- t/04recurrence.t

for some ideas on how to use the "ICal" parser/formatter - it makes it
easier to read/write recurrences from a file or database.

(reading the rfc2445 docs, I guess that ICal also supports spansets, but
I'm not sure)

About the API: 
when you said "It could then be extended ..." you mean another module,
right?
I think you are defining a lot of functionality, beyond "::Week".

- Flavio S. Glock


RFC: API for DateTime::Business:Week (was Re: Time Delta)

2003-10-02 Thread RIck Measham
Scott asked:
>> >* Here is DateTime 1
>> >* Here is DateTime 2
>> >* Here is the working week (Mon-Fri, 9-5) (or whatever we define)
>> >* Tell me the working hours between DateTime 1 and DateTime 2

> Rick Measham wrote:
>> G'day DateTimers,
>> Any clues on why the intersections don't create properly?

Flavio S. Glock replied:
> Rick:
> Creating a complex recurrence function is hard.
> It is much easier to use DT::Event::Recurrence:

Thanks Flavio,

Is anyone working on business modules yet? I figure your code would be a
great place to start:

$working_hours = new DateTime::Business::Week(
days  => [1 .. 5],
start => {hour => 9,  minute => 0},
end   => {hour => 17, minute => 30}
);

and, for those with more complex weeks:

$working_hours = new DateTime::Business::Week(
{
days  => [3 .. 5],
start => {hour => 9,  minute => 0},
end   => {hour => 17, minute => 30}
},
{
days  => 6,
start => {hour => 9,  minute => 0},
end   => {hour => 17, minute => 00}
},
{
days  => 7,
start => {hour => 10,  minute => 30},
end   => {hour => 16, minute => 30}
},
);

Basically Business::Week->new would return an infinite spanset for all
working hours. 

It could then be extended to allow for spans so we can include historical
data:

$working_hours->history(
span => $span,
week => $business_week
);

And such things as a finite span:

$working_hours->set_start($dt1); # start of employment
$working_hours->set_end($dt2);   # sacked!

Then we could create other spansets for employee related information

$working_hours->public_holiday( $recurrence ); # or $span or $spanset
$working_hours->annual_leave( $span ); # or $spanset
$working_hours->sick_leave( $span ); # or $spanset

With/without parameters the above three functions would return spansets for
the time off work.

Then we can set a project for a particular span:

$working_hours->project( 
name => 'Project X',
span => $span, # or $spanset
);
If given a 'name' this method returns spanset for that project.

Now we can get a complete record of activity:

print $working_hours->activity( $datetime );
# Annual Leave   
print $working_hours->activity_span( $datetime )->min->ymd;
# 2003-08-12
print $working_hours->activity_span( $datetime )->max->ymd;
# 2003-08-19

print $working_hours->activity( $datetime2 );
# Project X   

print $working_hours->activity( $out_of_hours_datetime );
# undef

And we need a quick boolean test to see if the person was actually at work
print "Absent" unless $working_hours->at_work;


Comments/Thoughts/...?

Cheers!
Rick


-- 
Obviously the reply-to is a fake. Just change the 'spam-' to 'i' so that the
result sounds like why you go to an optometerist.


Re: DateTime::TimeZone :: dieing on non existing timezone

2003-10-02 Thread Flavio S. Glock
Mathieu wrote:
> 
> Hi,
>   i'm looking for a way to find out if a timezone is valid.
> If i want to check a timezone using this module i instanciate
> an object with the provided name:
>   my $otz = new DateTime::TimeZone( name => 'Europe/Paris' );
> This name is valid so no problem, but if i try:
>   my $otz = new DateTime::TimeZone( name => 'Europ/Paris' );
> the module dies and so my script.
> 
> I've modified the DateTime::TimeZone module so that it returns
> undef when the timezone name is not valid.
> 
> Is this the proper way to do it, or is there a simple solution
> to my problem i didn't spotted ? If it's the proper way is there
> any chance it will be included in a future release ?

---
  use DateTime::TimeZone;

  my $otz;
  eval {
$otz = new DateTime::TimeZone( name => 'Europ/Paris' );
  };

  unless ( $otz )
  {
  print "Got undef: $@";
  }

  print "And life goes on\n";

---
  Got undef: Invalid time zone name: Europ/Paris at
/usr/local/lib/perl5/site_perl/5.6.1/DateTime/TimeZone.pm line 69.
  And life goes on
---

- Flavio S. Glock


Re: Time Delta

2003-10-02 Thread Flavio S. Glock
Rick Measham wrote:
> 
> At 5:07 PM +1000 2/10/03, Scott Penrose wrote:
>
> >I am trying to do the age old problem...
> >
> >* Here is DateTime 1
> >* Here is DateTime 2
> >* Here is the working week (Mon-Fri, 9-5) (or whatever we define)
> >* Tell me the working hours between DateTime 1 and DateTime 2
> >
> >eg:
> >
> >   DateTime 1  DateTime 2  Difference
> >
> >   19/8/2003 16:35 20/8/2003 11:15 2:40
> >
> >or - 2 hours, 40 minutes
> >
> >What is the simplest, shortest way.
> 
[...]
> G'day DateTimers,
> Any clues on why the intersections don't create properly?

Rick:

Creating a complex recurrence function is hard. 
It is much easier to use DT::Event::Recurrence:

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

use Data::Dumper; # For displaying results

$datetime1 = DateTime->new(
year => 2003,
month => 8,
day => 19,
hour => 16,
minute => 35
);
$datetime2 = DateTime->new(
year => 2003,
month => 8,
day => 20,
hour => 11,
minute => 15
);

$span = DateTime::Span->from_datetimes(
start => $datetime1,
end   => $datetime2
);


$wd_start = DateTime::Event::Recurrence->weekly(
   days => [ 1,2,3,4,5 ],
   hours => [ 9 ],
);

$wd_end = DateTime::Event::Recurrence->weekly(
   days => [ 1,2,3,4,5 ],
   hours => [ 17 ],
);

$working_hours = DateTime::SpanSet->from_sets(
start_set => $wd_start,
end_set => $wd_end,
);

$relevent_work_hours = $working_hours->intersection( $span );

print Dumper($relevent_work_hours->duration->deltas);


$VAR1 = 'months';
$VAR2 = 0;
$VAR3 = 'days';
$VAR4 = 0;
$VAR5 = 'minutes';
$VAR6 = 160;
$VAR7 = 'seconds';
$VAR8 = 0;
$VAR9 = 'nanoseconds';
$VAR10 = 0;


- Flavio S. Glock


DateTime::TimeZone :: dieing on non existing timezone

2003-10-02 Thread Mathieu
Hi,
 i'm looking for a way to find out if a timezone is valid.
If i want to check a timezone using this module i instanciate
an object with the provided name:
 my $otz = new DateTime::TimeZone( name => 'Europe/Paris' );
This name is valid so no problem, but if i try:
 my $otz = new DateTime::TimeZone( name => 'Europ/Paris' );
the module dies and so my script.
I've modified the DateTime::TimeZone module so that it returns
undef when the timezone name is not valid.
Is this the proper way to do it, or is there a simple solution
to my problem i didn't spotted ? If it's the proper way is there
any chance it will be included in a future release ?
Thanks.

Mat

--- TimeZone-0.2502.pm  2003-10-02 12:48:00.0 +0200
+++ TimeZone-0.2503.pm  2003-10-02 12:28:42.0 +0200
@@ -66,7 +66,10 @@
 my $real_class = "DateTime::TimeZone::$subclass";
 eval "require $real_class";
-die "Invalid time zone name: $p{name}" if ( $@ );
+if ( $@ ) {
+ print STDERR "Invalid time zone name: $p{name}\n";
+ returnundef;
+}
 return $real_class->instance( name => $p{name}, is_olson => 1 );
 }


Re: Time Delta

2003-10-02 Thread Rick Measham
At 5:07 PM +1000 2/10/03, Scott Penrose wrote:
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
I am trying to do the age old problem...

* Here is DateTime 1
* Here is DateTime 2
* Here is the working week (Mon-Fri, 9-5) (or whatever we define)
* Tell me the working hours between DateTime 1 and DateTime 2
eg:

  DateTime 1  DateTime 2  Difference

  19/8/2003 16:35 20/8/2003 11:15 2:40

or - 2 hours, 40 minutes

What is the simplest, shortest way.


G'day Scott,
I promised a few months back to talk about DateTime sometime soon. 
Tell me when and I'll be there. The following *should* solve your 
problem, but doesn't. I get a strange error at the end when creating 
the intersection. To solve this (and maybe to get a better answer) 
I've CC'd this to the DateTime mailing list.

G'day DateTimers,
Any clues on why the intersections don't create properly?


use DateTime;
use DateTime::Span;
use DateTime::Set;
use DateTime::SpanSet;
use Data::Dumper; # For displaying results

$datetime1 = DateTime->new(
year => 2003,
month => 8,
day => 19,
hour => 16,
minute => 35
);
$datetime2 = DateTime->new(
year => 2003,
month => 8,
day => 20,
hour => 11,
minute => 15
);
$span = DateTime::Span->from_datetimes(
start => $datetime1,
end   => $datetime2
);
$wd_start = DateTime::Set->from_recurrence(
recurrence => sub {
# Tomorrow at 9 am
$_[0]->truncate( to => 'day' )->add( days => 1, hours => 9 );
# Add two days if it's Saturday
$_[0]->add( days => 2) if $_[0]->day == 6;
},
);
$wd_end = DateTime::Set->from_recurrence(
recurrence => sub {
# Tomorrow at 5pm
$_[0]->truncate( to => 'day' )->add( days => 1, hours => 17 );
# Add two days if it's Saturday
$_[0]->add( days => 2) if $_[0]->day == 6;
},
);
$working_hours = DateTime::SpanSet->from_sets(
start_set => $wd_start,
end_set => $wd_end,
);
$relevent_work_hours = $working_hours->intersection( $span );

print Dumper($relevent_work_hours->duration->deltas);