|
From: grinder <gr...@pe...> - 2001-12-01 15:07:28
|
Hello list, I downloaded the countdown script, because it seemed like a good place to start. My idea is to run all of the nms scripts on http://grinder.perlmonk.org/ to give them a bit of a shakeout. So I configured the date to be 1/1/3001, the countdown to the next millenium. Ran the script. Date has passed. Huh? Then it struck me... the date is based on epoch seconds. So I set the countdown to the end of the epoch. I can just about recite it from memory, 19/1/2038 and a few hours more. Date has passed. Turns out, something somewhere is cutting the dates off at an arbitrary limit: 23:59:29 31/12/2037. One other point: '%c' as a strftime date specifier is a little cryptic. I would tend to prefer '%H:%M:%S %d/%m/%Y'. Regardless of the broken way Americans deal with dates, this is a little more self-documenting and therefore would probably let people modify the format string without having to read the man page. Here's the thing though. The 2038 limit is a little feeble. Does Date::Calc know how to deal with dates beyond the end of the world (as we know it)? Why not eval a require of Date::Calc, and perform an error check on the date to see whether it is in bounds or not, according to whether we can use Date::Calc or not. Also, all those reverse @arrays is a bit ugly. Something needs to be done. Anyway, I haven't really done anything to the script yet, but there are a few things that might be worth diffing. Later, David "grinder" Landgren __DATA__ #! /usr/bin/perl -w # # $Id: countdown.pl,v 1.5 2001/11/25 11:39:38 gellyfish Exp $ # # $Log: countdown.pl,v $ # Revision 1.5 2001/11/25 11:39:38 gellyfish # * add missing use vars qw($DEBUGGING) from most of the files # * sundry other compilation failures # # Revision 1.4 2001/11/13 20:35:14 gellyfish # Added the CGI::Carp workaround # # Revision 1.3 2001/11/13 09:14:41 gellyfish # Added CGI::Carp # # Revision 1.2 2001/11/11 17:55:27 davorg # Small amount of post-import tidying :) # # Revision 1.1.1.1 2001/11/11 16:48:45 davorg # Initial import # use strict; use POSIX qw(strftime); use Time::Local; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser set_message); use vars qw($DEBUGGING); # Configuration # # $DEBUGGING must be set in a BEGIN block in order to have it be set before # the program is fully compiled. # This should almost certainly be set to 0 when the program is 'live' # BEGIN { $DEBUGGING = 0; } # @from_date = (yyyy,mm,dd,hh,mm,ss); # Which means: (year,month,day,hour,minute,second) my @from_date = (2037,12,31,23,59,59); my $date_fmt = '%d/%m/%Y %H:%M:%S'; # see 'man strftime' for more examples # $style is the URL of a CSS stylesheet which will be used for script # generated messages. This probably want's to be the same as the one # that you use for all the other pages. This should be a local absolute # URI fragment. my $style = '/grinder.css'; # End configuration BEGIN { my $error_message = sub { my ($message ) = @_; print "<h1>It's all gone horribly wrong</h1>"; print $message if $DEBUGGING; }; set_message($error_message); } $from_date[0] -= 1900; $from_date[1]--; my @diffs = ('X', 12, 'X', 24, 60, 60); if (my $query = query_string()) { $query =~ s/%2C/,/g; $query =~ s/=//g; @from_date = split(/,/, $query); } my @now = reverse((localtime)[0 .. 5]); my $from_date = strftime($date_fmt, reverse @from_date); my $now = strftime($date_fmt, reverse @now); print header(), start_html(-title => "Countdown to: $from_date", -style => {href => $style}); print h1("Countdown to: $from_date"), hr(); my $epoch_now = timelocal(reverse @now); my $epoch_future = timelocal(reverse @from_date); if ($epoch_now > $epoch_future) { print h2('Date has passed'), p("Current = $epoch_now, Target = $epoch_future."), end_html(); exit; } my @days = (31, is_leap($now[0]+1900) ? 29 : 28 , 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); my @diff = ('-') x 6; my @skip = () x 6; foreach (reverse 0 .. $#from_date) { # print "$_: [@from_date][@now][@diff]\n"; if ($from_date[$_] eq 'XX') { $skip[$_] = 1; next; } $diff[$_] = $from_date[$_] - $now[$_]; if ($diff[$_] < 0) { if ($_ == 0) { die "Argh!! Time travel not implemented"; } elsif ($_ == 2) { $diff[$_] += $days[$now[1]]; $now[$_ - 1]++; } else { $diff[$_] += $diffs[$_]; $now[$_ - 1]++; } } } #print " : [@from_date][@now][@diff]\n"; my @units = qw(Year Month Day Hour Minute Second); my $diff; for (0 .. $#diff) { next if $skip[$_]; $diff .= "$diff[$_] $units[$_]"; $diff .= 's' if $diff[$_] != 1; $diff .= "<br>\n"; } print p($diff); print hr(), p("It is currently $now"), end_html(); sub is_leap { my $y = shift; (!($y % 100) && !($y % 400)) || (($y % 100) && !($y % 4)); } __END__ |
|
From: iain t. <ic...@eh...> - 2001-12-01 15:27:59
|
* grinder (gr...@pe...) [02 Dec 2001 02:18]: [...] > One other point: '%c' as a strftime date specifier is a little > cryptic. I would tend to prefer '%H:%M:%S %d/%m/%Y'. Regardless of the > broken way Americans deal with dates, this is a little more > self-documenting and therefore would probably let people modify the > format string without having to read the man page. Personally, I'd use %b rather than %m - the one that puts 'Jul' in rather than '7'. It makes things a bit more explict which is great when one has to cope with the fact that you've got an international audience part of which expects m/d/y and the rest expects d/m/y. Just a thought. cheers, -- iain. <http://eh.org/~koschei/> |
|
From: Jonathan S. <gel...@ge...> - 2001-12-01 18:04:59
|
On Sat, 1 Dec 2001, grinder wrote: > Hello list, > > I downloaded the countdown script, because it seemed like > a good place to start. My idea is to run all of the nms > scripts on http://grinder.perlmonk.org/ to give them a bit > of a shakeout. > > So I configured the date to be 1/1/3001, the countdown to > the next millenium. Ran the script. Date has passed. > > Huh? > > Then it struck me... the date is based on epoch seconds. > So I set the countdown to the end of the epoch. I can > just about recite it from memory, 19/1/2038 and a few > hours more. > > Date has passed. > > Turns out, something somewhere is cutting the dates off > at an arbitrary limit: 23:59:29 31/12/2037. > > One other point: '%c' as a strftime date specifier is a > little cryptic. I would tend to prefer '%H:%M:%S %d/%m/%Y'. > Regardless of the broken way Americans deal with dates, > this is a little more self-documenting and therefore > would probably let people modify the format string > without having to read the man page. > > Here's the thing though. The 2038 limit is a little feeble. Unfortunately it is a fixed limit in the implementation of most operating systems (this is not Perl's fault). The time_t variable is (in most implementations) a 32 bit variable which (if defined as starting at 01/01/1970 as it is in POSIX ) runs out sometime in April 2038. I guess we should document this but thats about it I'm afraid ... /J\ -- Jonathan Stowe | <http://www.gellyfish.com> | This space for rent | |
|
From: Jonathan S. <gel...@ge...> - 2001-12-01 18:08:07
|
On Sat, 1 Dec 2001, grinder wrote: > > One other point: '%c' as a strftime date specifier is a > little cryptic. I would tend to prefer '%H:%M:%S %d/%m/%Y'. > Regardless of the broken way Americans deal with dates, > this is a little more self-documenting and therefore > would probably let people modify the format string > without having to read the man page. > In more recent versions of the code I am documenting the replacement parameters - I guess that I hadn't got round to the countdown script yet :) /J\ -- Jonathan Stowe | <http://www.gellyfish.com> | This space for rent | |
|
From: Joseph F. R. <rya...@os...> - 2001-12-02 00:59:53
|
> > One other point: '%c' as a strftime date specifier is a > > little cryptic. I would tend to prefer '%H:%M:%S %d/%m/%Y'. > > Regardless of the broken way Americans deal with dates, > > this is a little more self-documenting and therefore > > would probably let people modify the format string > > without having to read the man page. > > > >In more recent versions of the code I am documenting the replacement >parameters - I guess that I hadn't got round to the countdown script yet >:) I had been working on countdown.pl before "Crunch time" (Finals week and the week before), and although this wasn't one of the issues I had fixed (hadn't thought of it! :P). I'll fix it later tonight, when I need a break from studying. Thanks for pointing it out. |
|
From: Joseph F. R. <rya...@os...> - 2001-12-02 01:07:56
|
I finally got around to fully updating search.pl to use File::Find. Since I still can't get CVS to work (not even on cyg-win), I'll list the updates here and put the code on my perlmonk site at: http://jryan.perlmonk.org/nms/search.txt # Revision 2.0 2001/12/01 7:30:30 jfryan # * Redid Search Algorithm using File::Find; backwards compatibility is ensured # * Added \Q\E to safely include search terms in regexp # * Removed archaic %FORM hash, and also added search defaults and error handling # * Split return_html into 3 separate functions. Also made them work, unlike return_html, which did not ;) # * Added a @blocked array to the config, defaulted it to empty. @blocked will filter out any files within a directory listed in @blocked # * Changed $style so that it can be set to '' to not use a style sheet. Also, I changed the default information to point to NMS, and not Matt's site at worldwidemart. I thought that would make sense since the whole point of the project was to dissuade people from using Matt's scripts. |
|
From: Jonathan S. <gel...@ge...> - 2001-12-02 10:30:17
|
On Sat, 1 Dec 2001, Joseph F. Ryan wrote: > I finally got around to fully updating search.pl to use File::Find. Since > I still can't get CVS to work (not even on cyg-win), I'll list the updates > here and put the code on my perlmonk site at: > http://jryan.perlmonk.org/nms/search.txt Right, I merged that in with one small change which was to make the wanted subroutine for find() a named subroutine rather than a closure. The closure is a nice idea and does reduce the number of global variables but it is a little more difficult to understand. Nice one /J\ -- Jonathan Stowe | <http://www.gellyfish.com> | This space for rent | |
|
From: Joseph F. R. <rya...@os...> - 2001-12-02 01:32:13
|
I updated the countdown.pl script as per previous suggestions, and it can be found at: http://jryan.perlmonk.org/nms/countdown.txt Also, if someone can upload the countdown.pl (http://jryan.perlmonk.org/nms/countdown.txt) and search.pl (http://jryan.perlmonk.org/nms/search.txt) on the CVS, I would be most greatful, as I am still unable to make the damn thing work. :) |
|
From: Jonathan S. <gel...@ge...> - 2001-12-02 10:32:47
|
On Sat, 1 Dec 2001, Joseph F. Ryan wrote: > I updated the countdown.pl script as per previous suggestions, and it can > be found at: http://jryan.perlmonk.org/nms/countdown.txt > > Also, if someone can upload the countdown.pl > (http://jryan.perlmonk.org/nms/countdown.txt) and search.pl > (http://jryan.perlmonk.org/nms/search.txt) on the CVS, I would be most > greatful, as I am still unable to make the damn thing work. :) > > I've stuck it in the CVS. Maybe if you can get on IRC sometime we can talk you through getting the CVS to work for you. That'll be '#london.pm' on london.rhizomatic.net .... /J\ -- Jonathan Stowe | <http://www.gellyfish.com> | This space for rent | |