Skip to content

Instantly share code, notes, and snippets.

@halorgium
Created September 11, 2008 07:58
Show Gist options
  • Save halorgium/10180 to your computer and use it in GitHub Desktop.
Save halorgium/10180 to your computer and use it in GitHub Desktop.
class DateTime
def httpdate
t = dup.utc
sprintf('%s, %02d %s %d %02d:%02d:%02d GMT',
Time::RFC2822_DAY_NAME[t.wday],
t.day, Time::RFC2822_MONTH_NAME[t.mon-1], t.year,
t.hour, t.min, t.sec)
end
def utc
to_s =~ /([-+])(\d\d:\d\d)$/
sign, hours, mins = $~.to_a[1..3]
diff = hours.to_i * 60 + mins.to_i
signed_diff = sign == "-" ? -diff : diff
self - (signed_diff / 1440.0)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment