in reply to Re^5: Parsing/regex question
in thread Parsing/regex question
I actually do want the date half way around the world :) The 'local' was taken out because the script is still a work-in-progress, so to speak.
I've got the following now:
... my $tz_ny = "America/New_York"; my $tz_ln = "Europe/London"; my $tz_tk = "Asia/Tokyo"; my $tz_hk = "Asia/Hong_Kong"; my $tz_se = "Asia/Seoul"; my $tz_mo = "Europe/Moscow"; ... if ($region =~ /ny/) { $today_tmp = DateTime->now( time_zone => $tz_ny); print "it is $today_tmp now in NY\n"; $tomorrow_tmp = DateTime->now()->add( days => 1 ); $yesterday_tmp = DateTime->now()->subtract( days => 1 ); } elsif ($region =~ /ln/) { $today_tmp = DateTime->now( time_zone => $tz_ln); print "it is $today_tmp now in LN\n"; $tomorrow_tmp = DateTime->now()->add( days => 1 ); $yesterday_tmp = DateTime->now()->subtract( days => 1 ); } elsif ($region =~ /tk/) { $today_tmp = DateTime->now( time_zone => $tz_tk); print "it is $today_tmp now in TK\n"; $tomorrow_tmp = DateTime->now()->add( days => 1 ); $yesterday_tmp = DateTime->now()->subtract( days => 1 ); } elsif ($region =~ /hk/) { $today_tmp = DateTime->now( time_zone => $tz_hk); print "it is $today_tmp now in HK\n"; $tomorrow_tmp = DateTime->now()->add( days => 1 ); $yesterday_tmp = DateTime->now()->subtract( days => 1 ); } elsif ($region =~ /se/) { $today_tmp = DateTime->now( time_zone => $tz_se); print "it is $today_tmp now in SE\n"; $tomorrow_tmp = DateTime->now()->add( days => 1 ); $yesterday_tmp = DateTime->now()->subtract( days => 1 ); } elsif ($region =~ /mo/) { $today_tmp = DateTime->now( time_zone => $tz_mo); print "it is $today_tmp now in MO\n"; $tomorrow_tmp = DateTime->now()->add( days => 1 ); $yesterday_tmp = DateTime->now()->subtract( days => 1 ); } $today = $today_tmp->mdy('/'); $tomorrow = $tomorrow_tmp->mdy('/'); $yesterday = $yesterday_tmp->mdy('/'); print "Today ($region): $today -=- "; print "Tomorrow ($region): $tomorrow -=- "; print "Yesterday ($region): $yesterday -=- "; $next_business_day = `$holiday_script "$today" $region`; chomp($next_business_day); print "Next business day: $next_business_day\n"; $today_local_tmp = DateTime->now( time_zone => 'local'); $tomorrow_local_tmp = DateTime->now()->add( days => 1 ); $yesterday_local_tmp = DateTime->now()->subtract( days => 1 ); $today_local = $today_local_tmp->mdy('/'); $tomorrow_local = $tomorrow_local_tmp->mdy('/'); $yesterday_local = $yesterday_local_tmp->mdy('/'); print "Today (local (NY) ): $today_local -=- "; print "Tomorrow (local (NY) ): $tomorrow_local -=- "; print "Yesterday (local (NY) ): $yesterday_local -=- "; $next_business_day_local = `$holiday_script "$today" ny`; chomp($next_business_day_local); print "Next business day (local (NY) ): $next_business_day_local\n"; ...
So in essence I have 2 variables - one for whatever timezone I'm interested in at the moment, and another one that always contains local time.
As for now and today - was just playing around and replaced it, then never switched it back :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Parsing/regex question
by ikegami (Patriarch) on Jul 08, 2009 at 17:55 UTC | |
by vxp (Pilgrim) on Jul 08, 2009 at 19:04 UTC |