[lug] Hodie!
Tom Christiansen
tchrist at perl.com
Wed Feb 11 17:40:15 MST 2009
This is really kinda fun. Or at least, *I* think so.
As some of you know, something very, very special is about to occur, and
it's going to happen just 1½ minutes shy of 2 hours past my coming birthday.
The closeness of these 2 events I have long foreseen, and anticipated.
Here's what it is: your computer's internal time (a.k.a. "the epoch",
measured in number of seconds since 1970) hits the unique figure of
1234567890, thus lining up all the digits the same way they're lined
up at the top of your keyboard.
Isn't that *special*? :-)
It really is a Magic Moment in history. This is readily shown
by typing a simple perl command into any shell window:
perl -le 'print scalar localtime(1234567890)'
Here in Boulder, I get back:
Fri Feb 13 16:31:30 2009
However, when *your* clock shows the magic moment happening varies quite a
bit, depending on where you live. I below show how different this can be.
Enjoy!
Following the output is the program that generates this, but CAVEAT LECTOR!
--tom
Here's the regular run here at home. It says:
I was born at E -217132020: Wed Feb 13 15:33:00 CST 1963.
I was born at E -217132020: Wed Feb 13 14:33:00 MST 1963.
I was born at E -217132020: Wed Feb 13 21:33:00 GMT 1963.
I was born at E -217132020: Wed Feb 13 21:33:00 UTC 1963.
Next birthday at E+1234560780, Fri Feb 13 14:33:00 MST 2009.
Magic moment is E+1234567890: Fri Feb 13 16:31:30 MST 2009.
Given it is now E+1234394951, I'm 1,451,526,971 seconds old.
Seconds to the magic moment: 172,940
Seconds until next birthday: 165,830
Magic moment is just 7,110 seconds past my birthday!
[ Now I'll trim the stuff that won't change ]
Assuming I'm in America/Los_Angeles....
I was born at E -217132020: Wed Feb 13 15:33:00 CST 1963.
I was born at E -217132020: Wed Feb 13 13:33:00 PST 1963.
I was born at E -217132020: Wed Feb 13 21:33:00 GMT 1963.
I was born at E -217132020: Wed Feb 13 21:33:00 GMT 1963.
Next birthday at E+1234560780, Fri Feb 13 13:33:00 PST 2009.
Magic moment is E+1234567890: Fri Feb 13 15:31:30 PST 2009.
Assuming I'm in US/Hawaii....
I was born at E -217132020: Wed Feb 13 15:33:00 CST 1963.
I was born at E -217132020: Wed Feb 13 11:33:00 HST 1963.
I was born at E -217132020: Wed Feb 13 21:33:00 GMT 1963.
I was born at E -217132020: Wed Feb 13 21:33:00 UTC 1963.
Next birthday at E+1234560780, Fri Feb 13 11:33:00 HST 2009.
Magic moment is E+1234567890: Fri Feb 13 13:31:30 HST 2009.
Assuming I'm in America/Sao_Paulo....
I was born at E -217132020: Wed Feb 13 15:33:00 CST 1963.
I was born at E -217132020: Wed Feb 13 18:33:00 BRT 1963.
I was born at E -217132020: Wed Feb 13 21:33:00 GMT 1963.
I was born at E -217132020: Wed Feb 13 21:33:00 GMT 1963.
Next birthday at E+1234560780, Fri Feb 13 19:33:00 BRST 2009.
Magic moment is E+1234567890: Fri Feb 13 21:31:30 BRST 2009.
Given it is now E+1234395599, I'm 1,451,527,619 seconds old.
Assuming I'm in Canada/Newfoundland....
I was born at E -217132020: Wed Feb 13 15:33:00 CST 1963.
I was born at E -217132020: Wed Feb 13 18:03:00 NST 1963.
I was born at E -217132020: Wed Feb 13 21:33:00 GMT 1963.
I was born at E -217132020: Wed Feb 13 21:33:00 UTC 1963.
Next birthday at E+1234560780, Fri Feb 13 18:03:00 NST 2009.
Magic moment is E+1234567890: Fri Feb 13 20:01:30 NST 2009.
Assuming I'm in Europe/Paris....
I was born at E -217132020: Wed Feb 13 15:33:00 CST 1963.
I was born at E -217132020: Wed Feb 13 22:33:00 CET 1963.
I was born at E -217132020: Wed Feb 13 21:33:00 GMT 1963.
I was born at E -217132020: Wed Feb 13 21:33:00 UTC 1963.
Next birthday at E+1234560780, Fri Feb 13 22:33:00 CET 2009.
Magic moment is E+1234567890: Sat Feb 14 00:31:30 CET 2009.
Assuming I'm in Australia/Melbourne....
I was born at E -217132020: Wed Feb 13 15:33:00 CST 1963.
I was born at E -217132020: Thu Feb 14 07:33:00 EST 1963.
I was born at E -217132020: Wed Feb 13 21:33:00 GMT 1963.
I was born at E -217132020: Wed Feb 13 21:33:00 UTC 1963.
Next birthday at E+1234560780, Sat Feb 14 08:33:00 EST 2009.
Magic moment is E+1234567890: Sat Feb 14 10:31:30 EST 2009.
Assuming I'm in America/New_York....
I was born at E -217132020: Wed Feb 13 15:33:00 CST 1963.
I was born at E -217132020: Wed Feb 13 16:33:00 EST 1963.
I was born at E -217132020: Wed Feb 13 21:33:00 GMT 1963.
I was born at E -217132020: Wed Feb 13 21:33:00 UTC 1963.
Next birthday at E+1234560780, Fri Feb 13 16:33:00 EST 2009.
Magic moment is E+1234567890: Fri Feb 13 18:31:30 EST 2009.
Assuming I'm in Pacific/Auckland....
I was born at E -217132020: Wed Feb 13 15:33:00 CST 1963.
I was born at E -217132020: Thu Feb 14 09:33:00 NZST 1963.
I was born at E -217132020: Wed Feb 13 21:33:00 GMT 1963.
I was born at E -217132020: Wed Feb 13 21:33:00 UTC 1963.
Next birthday at E+1234560780, Sat Feb 14 10:33:00 NZDT 2009.
Magic moment is E+1234567890: Sat Feb 14 12:31:30 NZDT 2009.
==================================================================
#!/usr/bin/perl
#
# hodie - show countdown till my birthday and the magic moment
#
# Tom Christiansen
# tchrist at perl.com
#
# Wed Feb 11 17:05:38 MST 2009
#
################
use strict;
use warnings FATAL => "all";
use Time::localtime qw[ :DEFAULT ];
use Time::Local qw[ timelocal ];
use POSIX qw[ strftime ];
use constant {
RIGHT_NOW => $^T,
EPOCH_FMT => q(E%+11d), # epoch format for printf
DATE_FMT => q(%+), # date format for strftime
# aka: Greenwich, UTC, Universal, Zulu
STD_TIMEZONE => "GMT",
BIRTH_ZONE => "America/Chicago", # er: Beloit, Wisconsin
# aka: 1,234,567,890 or even 1_234_567_890
MAGIC_MOMENT => 1234567890,
#########################
## quam olim natus fui ##
#########################
BIRTH_YEAR => 1963,
BIRTH_MON => 1, # ( 0 .. 11 )
BIRTH_MDAY => 13,
BIRTH_HOUR => 15, # 3pm
BIRTH_MIN => 33,
BIRTH_SEC => 0, # NPI
};
our(
$EF, # interpolable version of EPOCH_FMT
$BZERO, # hora natalis mea
$BANNO, # anniversarius ille
);
main();
exit();
die "NOT REACHED";
##########################################################
sub commify {
local $_ = @_ ? shift : $_;
while (s/^([-+]?\d+)(\d{3})/$1,$2/) { ;;; }
return $_;
}
BEGIN {
last unless 1 == eval q{
use Scalar::Util qw(set_prototype);
1;
};
set_prototype( \&commify,
( $] >= 5.0_10_000 )
? q(_)
: q(;$)
);
}
sub main {
nits();
nascor();
magical_moments();
}
sub nits {
$EF = EPOCH_FMT;
}
sub zdate($) { strftime( DATE_FMT, CORE::gmtime( $_[0] )) }
sub ldate($) { strftime( DATE_FMT, CORE::localtime( $_[0] )) }
sub date($) { &ldate }
sub diem($) {
my $era = shift();
printf "I was born at $EF: %s.\n", $era, date($era);
}
sub magical_moments {
my $senex = ( RIGHT_NOW - $BZERO );
my $expecto = ( $BANNO - RIGHT_NOW );
my $mdelta = ( MAGIC_MOMENT - RIGHT_NOW );
my $mgksex = ( MAGIC_MOMENT - $BANNO );
diem($BZERO);
printf "Next birthday at $EF, %s.\n", $BANNO, date($BANNO);
printf "Magic moment is $EF: %s.\n",
MAGIC_MOMENT, date(MAGIC_MOMENT);
printf "Given it is now $EF, I'm %s seconds old.\n\n",
RIGHT_NOW, commify($senex);
printf "Seconds to the magic moment: %s\n", commify($mdelta);
printf "Seconds until next birthday: %s\n", commify($expecto);
printf "Magic moment is just %s seconds past my birthday!\n",
commify($mgksex);
}
sub nascor {
# local() to assure extant TZ restoration/deletion
local $ENV{TZ} = BIRTH_ZONE;
my $b_year = BIRTH_YEAR;
my $b_mon = BIRTH_MON;
my $b_mday = BIRTH_MDAY;
my $b_hour = BIRTH_HOUR;
my $b_min = BIRTH_MIN;
my $b_sec = BIRTH_SEC;
# good thing we support negative epochal moments here
my $b_time = timelocal( $b_sec, $b_min, $b_hour,
$b_mday, $b_mon, $b_year );
# use following (unsigned) cast to defeat sign extension
### $b_time = unpack("I", pack("i", $b_time));
$BZERO = $b_time;
$BANNO = do {
my ($annus, $anniverse);
$annus = 1900 + localtime(RIGHT_NOW)->year();
$anniverse = timelocal( $b_sec, $b_min, $b_hour,
$b_mday, $b_mon, $annus );
if ($anniverse < RIGHT_NOW) {
$anniverse = timelocal( $b_sec, $b_min, $b_hour,
$b_mday, $b_mon, (1 + $annus) );
}
$anniverse; # do{} retval
};
diem($BZERO);
{
no warnings qw(redefine);
local *date = \&zdate; # so shoot me
$ENV{TZ} = STD_TIMEZONE;
diem($BZERO);
### libc bug? docs say this shouldn't count leap-seconds now!!
$ENV{TZ} = q(); # UTC, no leap-seconds
diem($BZERO);
# nother bug: on some systems, claims UTC above; on others, GMT
}
}
die "STILL NOT REACHED";
More information about the LUG
mailing list