Gossamer Forum
Home : Gossamer Threads Inc. : Discussion :

GT::Date - Determining whether it is before a particular time

Quote Reply
GT::Date - Determining whether it is before a particular time
Quote:
Hi,

(I think that this is the appropriate forum for discussing the GT:: Modules, despite the forum description).

I'm trying to determine whether or not the time is before 6pm using GT::Date, but at the moment neither date_is_greater or date_is_smaller returns true. Any ideas how I can overcome this (or what I'm doing wrong?)

Code:
#!/usr/bin/perluse GT::Date qw/:all/;my $days = 4;##### Time Formats ################
$sec_fmt = '%HH%:%MM%:%ss%';
$orig_fmt = '%yyyy%-%mm%-%dd% %HH%:%MM%:%ss%';
###############################
date_set_format($orig_fmt);my $date = date_get();
my $deadline = date_get (time + ($days * 86400)); print qq|Order Date: $date
Deadline: $deadline
|;# If the time is after 6:00pm, then we should give everyone an extra day as it's
# so late in the day.
$now_s = date_transform ($date, $orig_fmt, $sec_fmt);
$sixpm_s = '18:00:00';
date_set_format($sec_fmt); print "Comparing $now_s with $sixpm_s\n";
if (date_is_greater($sixpm_s, $now_s)) {
print "It is after 6pm ($sixpm_s > $now_s )\n";
}
if (date_is_smaller($sixpm_s, $now_s)) {
print "It is before 6pm ($now_s < $sixpm_s)\n";
}
From the GT::Date docs:
Quote:
date_is_greater[/url]

Returns 1 if argument 1 is greater then argument 2, otherwise 0.


date_is_smaller[/url]

Returns 1 if argument 1 is smaller then argument 2, otherwise 0.

Last edited by:

cwi: Aug 27, 2003, 1:31 PM
Quote Reply
Re: [cwi] GT::Date - Determining whether it is before a particular time In reply to
Sorry, all the line breaks in the code are munged but hopefully you should get the gist of it.
Quote Reply
Re: [cwi] GT::Date - Determining whether it is before a particular time In reply to
Hi,

Best thing to do would be:

my @time = GT::Date::parse_format($date, "format string");
if ($time[2] >= 18) {
# after 6pm
}

@time is an array like you would get from localtime:

Code:
# 0 1 2 3 4 5 6 7 8
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] GT::Date - Determining whether it is before a particular time In reply to
Wow, thanks Alex!

Unfortunately this doesn't seem to produce anything for me:

Code:


##### Time Formats ################
$fmt = '%yyyy%-%mm%-%dd% %HH%:%MM%:%ss%';
###############################
date_set_format($orig_fmt);

my $date = date_get();
my $deadline = date_get (time + ($days * 86400));

print qq|Order Date: $date
Deadline: $deadline
|;

my @times =GT ::Date::parse_format($date, $fmt);

print "producing anything? - $times->[0] - \n";

if ($time->[2] >= 18) {
print "$times->[2] It is after 6\n";
}

Last edited by:

cwi: Aug 27, 2003, 2:45 PM