Skip to content

Instantly share code, notes, and snippets.

@fglock
Created August 18, 2017 17:05
Show Gist options
  • Save fglock/cf1117ad000b41d9e5dbee6fa8b78993 to your computer and use it in GitHub Desktop.
Save fglock/cf1117ad000b41d9e5dbee6fa8b78993 to your computer and use it in GitHub Desktop.
DateTime::Event::ICal test with time zone
#!/bin/perl -w
# Copyright (c) 2003 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.
#
# modified from Date::Set tests
#
use strict;
# use warnings;
use Test::More tests => 3;
use DateTime::Span;
BEGIN { use_ok('DateTime::Event::ICal') };
sub str {
my $iter = $_[0]->iterator;
my @result;
while ( my $dt = $iter->next ) {
push @result, "TZID=" . $dt->time_zone->name . ":" . $dt->datetime
if ref( $dt );
};
return join( ',', @result );
}
my ($title, $a, $a2, $b, $period, $RFC);
# DATES
my $dt19950101 = DateTime->new(
year => 1995 );
my $dt19990101 = DateTime->new(
year => 1999 );
my $dt19970902T090000_tz = DateTime->new(
year => 1997, month => 9, day => 2, hour => 9,
time_zone => 'America/New_York',
);
my $period_1995_1999 = DateTime::Span->new(
start => $dt19950101, end => $dt19990101 );
$title="*** Daily for 10 occurrences ***";
#
# DTSTART;TZID=US-Eastern:19970902T090000
# recur_by_rule:FREQ=DAILY;COUNT=10
#
# ==> (1997 9:00 AM EDT)September 2-11
#
$a = DateTime::Event::ICal->recur(
dtstart => $dt19970902T090000_tz ,
freq => 'daily',
count => 10 )
->intersection( $period_1995_1999 );
is("". str($a),
'TZID=America/New_York:1997-09-02T09:00:00,TZID=America/New_York:1997-09-03T09:00:00,' .
'TZID=America/New_York:1997-09-04T09:00:00,TZID=America/New_York:1997-09-05T09:00:00,' .
'TZID=America/New_York:1997-09-06T09:00:00,TZID=America/New_York:1997-09-07T09:00:00,' .
'TZID=America/New_York:1997-09-08T09:00:00,TZID=America/New_York:1997-09-09T09:00:00,' .
'TZID=America/New_York:1997-09-10T09:00:00,TZID=America/New_York:1997-09-11T09:00:00', $title);
# with time_zone
$a = DateTime::Event::ICal->recur(
dtstart => $dt19970902T090000_tz ,
freq => 'daily',
count => 10 )
->set_time_zone( "America/New_York" )
->intersection( $period_1995_1999 );
is("". str($a),
'TZID=America/New_York:1997-09-02T09:00:00,TZID=America/New_York:1997-09-03T09:00:00,' .
'TZID=America/New_York:1997-09-04T09:00:00,TZID=America/New_York:1997-09-05T09:00:00,' .
'TZID=America/New_York:1997-09-06T09:00:00,TZID=America/New_York:1997-09-07T09:00:00,' .
'TZID=America/New_York:1997-09-08T09:00:00,TZID=America/New_York:1997-09-09T09:00:00,' .
'TZID=America/New_York:1997-09-10T09:00:00,TZID=America/New_York:1997-09-11T09:00:00', $title);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment