workspace.dateToISO8601


File: dateToISO8601.sit.hqx
Server: www.orange-road.com
Modified: 1/20/98; 12:50:57 AM
Size: 2K
Owner: khagler@orange-road.com
Attachments: None

dateToISO8601

This is a fairly simple utility script which takes a date (from clock.now(), for instance) and returns a string in ISO 8601 format. While reading up on proposals for metadata, I noticed that all of them used this date format, so I decided that it would be a good idea to write a simple conversion script. dateToISO601 also exists inside the latest version of my pageheaderV macro (which is what I wrote it for), but I thought it might come in handy by itself.

Here is the source code:

on dateToISO8601 ( theDate = clock.now() ) {
	on addzero ( num ) { « add a leading zero to a single digit number
		if num^ < 10 {
			num^ = "0" + num^;
			}};«return ( num )
	local ( day, month, year, hour, minute, second, ISOString, timezone );
	date.get ( theDate, @day, @month, @year, @hour, @minute, @second );
	timezone = string.nthField ( tcpcmd.interfaces.rfcGetCurrentDate (), ' ', 7 ); « get the offset using TCPCMD
	if timezone == "+0000" { « see if we're in the GMT zone
		timezone = "Z"} « set time zone appropriately
	else { « we're somewhere else, so insert the colon in the time zone string
		timezone = string.insert ( ":", timezone, 4 )};
	bundle { « make sure there aren't any single-digit number here
		addzero ( @month );
		addzero ( @day );
		addzero ( @hour );
		addzero ( @minute );
		addzero ( @second )};
	ISOString = year + "-" + month + "-" + day + "T" + hour + ":" + minute + ":" + second + timezone;
	return ( ISOString )};
dateToISO8601()

Site scripted with Userland Frontier
This page was last built on Mon, Jun 15, 1998 using the Sysop Suite (V1.0f1) on a PowerWave running Frontier.