Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Newbie: Request help on creating CSV using timestamp data

by hippo (Canon)
on Nov 22, 2013 at 09:58 UTC ( #1063910=note: print w/replies, xml ) Need Help??

in reply to Newbie: Request help on creating CSV using timestamp data

It's good to see that your organisation keeps appointments to the precision of milliseconds!

You are going to need loops, file operations, maybe Text::CSV and most importantly an algorithm. How are the times assigned? Are they in APP.csv too? What other data is in APP.csv? What governs appointment length? You'll need to know the answers to these sorts of questions to produce a full solution.

  • Comment on Re: Newbie: Request help on creating CSV using timestamp data

Replies are listed 'Best First'.
Re^2: Newbie: Request help on creating CSV using timestamp data
by Anonymous Monk on Nov 22, 2013 at 13:12 UTC
    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..

      I'd start with making that easier to extend (and maintain). The snippet uses the default (builtin) localtime function, not the one returning a hashref or an object:

      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
        Using the perl version --> v5.8.8 built. Getting the following error using the above snippet,
        Use of uninitialized value in addition (+)

      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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1063910]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2018-07-22 07:01 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (452 votes). Check out past polls.