I have got the start and end time using the following code,
sub starttimestamp() {
my $st = localtime;
return sprintf( "%04d-%02d-%02dT%02d:%02d:%02d.000-0700",
$st->year + 1900, $st->mon + 1, $st->mday,
$st->hour, $st->min, $st->sec );
}
sub endtimestamp() {
my $et = localtime;
return sprintf( "%04d-%02d-%02dT%02d:%02d:%02d.000-0700",
$et->year + 1900, $et->mon + 1, $et->mday,
$et->hour, $et->min + 15, $et->sec );
}
Now, i need a logic where i can keep incrementing the start and end timestamps by 15 or 30 or 60 mins. Thus, having unique timestamps. But the criteria is that i need to have only 50 unique values for a week. Later, continue the same 50 timestamps for the next week and so on.. | [reply] [d/l] |
sub timestamp
{
my @st = localtime (shift);
return sprintf "%04d-%02d-%02dT%02d:%02d:%02d.000-0700",
$st[5] + 1900, ++$st[4], @st[3,2,1,0];
}
sub starttimestamp { return timestamp (time); }
sub endtimestamp { return timestamp (time + (15 * 60)); }
sub futuretimestamp { return timestamp (time + shift); }
my $fts = futuretimestamp (162 * 60 * 60); # Stamp 162 hours ahead
This way, there is only one location that defines the required format and several easy ways to use that.
Enjoy, Have FUN! H.Merijn
| [reply] [d/l] [select] |
Using the perl version --> v5.8.8 built.
Getting the following error using the above snippet,
Use of uninitialized value in addition (+)
| [reply] [d/l] |
Which version of Perl are you running? localtime returns a string when called in scalar context in the versions I use (<= 5.14). Perhaps you are using Time::Piece but have neglected to mention this?
Regardless, if you are going to do date/time arithmetic I would heartily recommend using any one of the available modules to do that for you rather than re-invent the wheel (otherwise you will have to start worrying about DST and leap years, etc.). Try one of Date::Manip, DateTime, Time::Piece, etc.
| [reply] |