[Brisbane-pm] Times and Dates

Martin Jacobs martin_jacobs at optusnet.com.au
Thu Sep 6 04:36:29 PDT 2007


Hi Perlmongers,

Here's a tricky one to do with times and dates.

I'm trying to generate a timeseries. The start and end time are user- 
defined, as is the timestep interval. So, if I start at 06/01/1990  
00:00:00, and end at 06/01/1990 00:12:00, and specify a timestep of 6  
minutes, I will get a timeseries like this...

06/01/1990 00:00:00
06/01/1990 00:06:00
06/01/1990 00:12:00

I will also be reading historic rainfall data, and applying the  
amount of rainfall to each timestep.

This requires that I read and write calendar date data in the human- 
friendly long format 01/01/1900 00:00:00, and do functions in terms  
of seconds since the epoch.

The sub for interpreting human-friendly time-date data into computer  
friendly seconds-since-epoch is as follows...

sub Calendar_date_string_to_timevalue {
	#Sub version 1.0
	#This sub converts a string to a time value
	#The format of the string is DD/MM/YYYY hh:mm:ss, e.g. 25/02/1990  
23:48:00
	#The sub parses the string, then uses timegm to calculate its value  
in terms of seconds since the Epoch
	my (%arg) 	= @_;
	my $t 		= $arg{arg1};
	my ($mday, $mon, $year, $hour, $min, $sec) = $$t =~ /(\d+)/g;
	$$t = timegm $sec, $min, $hour, $mday, $mon - 1, $year - 1900;
	}

I'm using timegm, because the timesteps must be mathematically  
consequential (every timestep must occur after the preceding  
timestep). There are other functions, but some do corrections for  
daylight savings etc, which I don't want.

My problem is that the output goes wrong for dates before 01/Jan/1970  
00:00:00 (I think, when timevalue in seconds-since-epoch is 0). Some  
of my timeseries may run to 1900, or even earlier, but the sub above  
refuses to generate a consequential series (1901, for example, gets  
interpreted as 2001).

BTW, I'm using Mac OSX, but the program I'm writing needs to run on  
any operating system.

Thanks in advance for any help...

Regards,
Martin
Visit my website...
http://web.mac.com/martin_jacobs1


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070906/56580942/attachment.html 


More information about the Brisbane-pm mailing list