Skip to content

Instantly share code, notes, and snippets.

View damonjmurray's full-sized avatar

Damon J. Murray damonjmurray

View GitHub Profile
@morkevicius
morkevicius / gist:10549920
Last active July 13, 2016 21:54 — forked from chancancode/gist:2830878
.net ticks to ruby time, ruby time to ticks 1.8.7
class Time
# See http://msdn.microsoft.com/en-us/library/system.datetime.ticks.aspx
# https://gist.github.com/chancancode/2830878
TICKS_SINCE_EPOCH = -(Time.utc(0001, 01, 01).to_i * 10000000)
def to_ticks
utc.to_i * 10000000 + TICKS_SINCE_EPOCH # ruby 1.8.7 doesn't support nano seconds so we're ok without it
# to_i * 10000000 + nsec / 100 - TICKS_SINCE_EPOCH
# <seconds from 1970-01-01 multiplied by 10 000 000> result is ticks + <self nsec which by default would be skipped>/100 result is ticks + ticks from 0001-01-01
end