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.




 
import std.stdio;
import std.format;
import std.datetime;
import std.algorithm;
 
enum months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
 
void main()
{
  // input	
  string date = "March 7 2009 7:30pm EST";
 
  // parsing date string to integer values
  string month, md, tz;
  int day, year, hour, minute;
  date.formattedRead("%s %d %d %d:%d%s %s", &month, &day, &year, &hour, &minute, &md, &tz);
  int mon = cast (int) months.countUntil(month) + 1;
 
  // convert to 24-hour 
  if (md == "pm")
    hour += 12;
 
  // create date from integer
  DateTime dt = DateTime(year, mon, day, hour, minute);
 
  // output
  writeln(dt);
  writeln(dt + 12.hours);
 
}
 
 