in reply to Re^4: Parsing/regex question
in thread Parsing/regex question

No, it doesn't. I thought you wanted the local date, not the date halfway around the world. If so, you introduced a bug by removing time_zone => 'local'. (Yeah, I had it misspelled.)

I'm also curious as to why you changed from today to now.

Replies are listed 'Best First'.
Re^6: Parsing/regex question
by vxp (Pilgrim) on Jul 08, 2009 at 15:50 UTC

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

      ow! Lookup table!!!
      my %tz_lkup = ( ny => "America/New_York", ln => "Europe/London", tk => "Asia/Tokyo", hk => "Asia/Hong_Kong", se => "Asia/Seoul", mo => "Europe/Moscow", ); my $today_dt = DateTime->now( time_zone => $tz_lkup{$region} ); my $tomorrow_dt = $today_dt->add( days => 1 ); my $yesterday_dt = $today_dt->subtract( days => 1 ); print "It is now $today_dt in ", uc($region), "\n"; ...

        awesome, much thanks!

        I'm always interested in seeing 'other ways' of accomplishing things, so I appreciate it.

        If you're really bored - here's the current version of the script.. Would you take a quick glance? :)

        It all works, but perhaps you'd spot something else (even simple stuff like the hash you suggested - simple, great, and reduces amount of lines :) ).