Skip to content

Instantly share code, notes, and snippets.

@sinkovsky
Created October 29, 2009 12:40
Show Gist options
  • Save sinkovsky/221413 to your computer and use it in GitHub Desktop.
Save sinkovsky/221413 to your computer and use it in GitHub Desktop.
to_tz(R, Tz) ->
Tz_offset = ((Tz#timezone.hour * 60) + Tz#timezone.minute) * 60,
R_offset = (((R#timestamp.timezone)#timezone.hour * 60) + (R#timestamp.timezone)#timezone.minute) * 60,
R_seconds = calendar:datetime_to_gregorian_seconds(to_datetime(R)),
New_seconds = R_seconds - R_offset + Tz_offset,
Datetime = calendar:gregorian_seconds_to_datetime(New_seconds),
{ok, New_R} = from_datetime(Datetime),
New_R#timestamp{timezone = Tz, fraction = R#timestamp.fraction}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment