Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

PipTime

by PipTigger (Hermit)
on Jan 22, 2001 at 12:23 UTC ( [id://53449]=CUFP: print w/replies, xml ) Need Help??

This is a little utility I use to compress the time for small project versions. I usually just use the first 3 characters for an archive name like 'pimp-1LN.tgz' for my Perl MP3 player project or something (which is almost done). `pt` takes it's own (un-parametered) output format as a parameter to be decoded.

Obviously `pt` won't be unique beyond 5 years but it will be compact which is more important for now && archiving big blocks every 5 years isn't so bad if it means daily versioning convenience (AFAIC). I thought maybe someone might like to use `pt` since I do (I've been doing it in my head for months for months {!days though (hehe)}). Please werd your "Y2K"-lecture carefully if you must reprimand me for my blatant ignorance of future-proofness. TTFN =).
#!/usr/bin/perl -w # pt (PipTime) is a simple tool created to en/decode the following fie +lds: # Year*12+Month, Day, Hour, Minute, Second into/from a terse 5-char +string. # The pt method will be unique until Feb. 2006. Created 1L7Mu AllNigh +ter =). # There's no !ERROR! checking so I might add some should it ever seem +useful. # I like to use brief encoded dates to version things so this lets me +quickly # choose a duration granularity as my next unique version descriptor. + TTFN. # All source code should be free! Code I have authority over is && sh +all be! # -Pip@BinQ.org use strict; my %mapz = (); # This guy will hold @valz as keys && indices as values + for lookups my @valz = ( 0..9, 'A'..'Z', 'a'..'z' ); # 0-61 dayz->V(31) minz->x(60 +) my @dayo = ( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sha" ); my @mnth = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ); my $tout = shift; my @time = localtime(); my $year = 1; if (defined($tout)) { for(my $i=0; $i<@valz; $i++) { $mapz{$valz[$i]} = $i; } @time = split //, $tout; splice(@time,5,127); # chop extras off! for(my $i=0; $i<5; $i++) { unless(defined($time[$i])) { $time[$i] = +0; } } while ($mapz{$time[0]} > 12) { $year++; $time[0] = $valz[$mapz{$time +[0]}-12]; } unshift(@time, $year+2000); print "$mnth[$mapz{$time[1]}-1] $mapz{$time[2]}, $time[0] "; if ($mapz{$time[3]} < 10) { print "0"; } print "$mapz{$time[3]}:"; if ($mapz{$time[4]} < 10) { print "0"; } print "$mapz{$time[4]}:"; if ($mapz{$time[5]} < 10) { print "0"; } print "$mapz{$time[5]}"; } else { $time[5] -= 101; $time[4] = $valz[(++$time[4]+(12*$time[5]))]; $time[3] = $valz[$time[3]]; $time[2] = $valz[$time[2]]; $time[1] = $valz[$time[1]]; $time[0] = $valz[$time[0]]; splice(@time,5,4); @time = reverse(@time); print @time; } # print "\n"; # hmmm...

-PipTigger
p.s. JAPM.

Replies are listed 'Best First'.
Re: PipTime
by dws (Chancellor) on Jan 22, 2001 at 13:05 UTC
    Run, don't walk, to your nearest Perl reference, and read up on printf.
      Thank you dws! I have made haste (@1M2C8) && lerned the error of my ways (I hope) by plumbing the Camel(2ndEd). I tried to correct my folly below... please be kind && direct me further if my understanding remains deficient. You have my gratitude!
      #... comments && setup varz if (defined($tout)) { for(my $i=0; $i<@valz; $i++) { $mapz{$valz[$i]} = $i; } @time = split //, $tout; splice(@time,5,($#time-5)); # chop extra! for(my $i=0; $i<5; $i++) { $time[$i]=0 unless defined($time[$i]); while ($mapz{$time[0]} > 12) { $time[0] = $valz[$mapz{$time[0]}-12]; $year++; } unshift(@time, $year+2000); printf "%s %d, %d %02d:%02d:%02d", $mnth[$mapz{$time[1]}-1], $mapz{$time[2]}, $time[0], $mapz{$time[3]}, $mapz{$time[4]}, $mapz{$time[5]}; } else { $time[5] -= 101; $time[4] = $valz[(++$time[4]+(12*$time[5]))]; $time[3] = $valz[$time[3]]; $time[2] = $valz[$time[2]]; $time[1] = $valz[$time[1]]; $time[0] = $valz[$time[0]]; printf "%s%s%s%s%s", $time[4],$time[3],$time[2],$time[1],$time[0]; } # print "\n"; # hmmm...
      -PipTigger
      p.s. I would've updated my initial post but hopefully another Monk can lern (like me) from the diff.
      p.p.s. %02d pads a decimal integer with "0" (zero) until it's 2 characters long.
Re: PipTime
by petral (Curate) on Jan 23, 2001 at 07:38 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://53449]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-19 04:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found