Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!uwm.edu!lll-winken!ames!haven!udel!princeton!phoenix!melon!viktor From: viktor@melon.Princeton.EDU (Viktor Dukhovni) Newsgroups: comp.lang.perl Subject: Re: reverse of localtime() Message-ID: <14243@phoenix.Princeton.EDU> Date: 4 Mar 90 21:35:24 GMT References: <1176@frankland-river.aaii.oz.au> <1990Mar4.034414.25460@pegasus.com> Sender: news@phoenix.Princeton.EDU Lines: 68 -----------------Cut------------------ #! /usr/bin/perl ;# ;# depending on whether localtime takes signed or unsigned args, ;# this should work for years between ~1902 and ~2038 or ;# ~1970 and ~2106 sub cmpdate { local($tse,$tmi,$tho,$tda,$tmo,$tyr,$foo1,$foo2,$foo3, $se,$mi,$ho,$da,$mo,$yr) = @_; if ( $tyr != $yr ) { return($tyr - $yr) ; } if ( $tmo != $mo ) { return($tmo - $mo) ; } if ( $tda != $da ) { return($tda - $da) ; } if ( $tho != $ho ) { return($tho - $ho) ; } if ( $tmi != $mi ) { return($tmi - $mi) ; } if ( $tse != $se ) { return($tse - $se) ; } } sub unctime { local(@args) = @_; local($bit); local($t) = 0x0; local($maxtime,$mintime) ; if (do cmpdate(localtime(0x80000000),localtime(0)) > 0 ) { $maxtime=0x80000000; $mintime=0x0; $bit=0x80000000; } else { $maxtime=0x7fffffff; $mintime=0x80000000; $bit=0x40000000; $t=$mintime if(do cmpdate(localtime(0),@args) > 0); } die "Date out of range\n" if (do cmpdate(localtime($maxtime),@args) < 0); die "Date out of range\n" if (do cmpdate(localtime($mintime),@args) > 0); while ( $bit != 0 ) { $t|=$bit if (do cmpdate(localtime($t|$bit),@args) <= 0) ; $bit >>= 1; } $t; } printf stderr "Please enter se/mi/ho/da/mo/yr "; chop($date = ) ; $time=do unctime(split(/\//,$date)) ; print "$time <- ",join("/",localtime($time)),"\n" ; ----------------Cut--------------- -- Viktor Dukhovni : ARPA <...!uunet!princeton!math!viktor> : UUCP