Task

Given the date string "March 7 2009 7:30pm EST", 

output the time 12 hours later in any human-readable format.

As extra credit, display the resulting time in a time zone different from your own.




twelve_hours := proc(str)
	local dt, zone;
	local months := ["January","February","March","April","May","June","July","August","September","October","November","December"];
	dt := StringTools:-ParseTime("%B %d %Y %l:%M%p", str);
	zone := StringTools:-RegSplit(" ", str)[-1];
	dt := Date(dt:-year, dt:-month, dt:-monthDay, dt:-hour, dt:-minute, timezone = zone);
	dt := dt + 12 * Unit(hours);
	printf("%s %d %d ", months[Month(dt)], DayOfMonth(dt), Year(dt));
	if (HourOfDay(dt) >= 12) then
		printf("%d:%dpm ", HourOfDay(dt)-12, Minute(dt));
	else
		printf("%d:%dam ", HourOfDay(dt), Minute(dt));
	end if;
	printf(TimeZone(dt));
end proc;
 