Nikky
06/19/2021, 11:07 AMdwHighDateTime
and dwLowDateTime
which are there so that a 64 bit value can be split into the lower and upper 32 bit
how would i split a kotlin Long into 2 UInt (DWORD) values ?
or can i just write a Long value to the FILETIME
struct via some unsafe operation ?Dominaezzz
06/19/2021, 12:23 PMnapperley
06/20/2021, 1:39 AMNikky
06/20/2021, 11:42 AMJoakimForslund
06/21/2021, 7:03 AMNikky
06/21/2021, 9:59 AM>>
<<
&
&=
|
|=
^
^=
, etc and have to use calls like a.shr(b)
or a = a or b
instead
it makes converting code that uses these operators complicated and nested in brackets
and functions have a different order of evaluation than operators do.. so you need to keep that in mind as wellnapperley
06/21/2021, 8:29 PMilya.gorbunov
06/23/2021, 11:06 AMapparently overflowing that value in kotlinx-datetime leads to subtracting time..@Nikky Could you provide more details on that? What operation has overflown?
Nikky
06/23/2021, 11:42 AMval windowsEpoch = LocalDateTime(1601, Month.JANUARY, 1, 0, 0).toInstant(TimeZone.UTC)
val lastModifiedInstant = Instant.fromEpochMilliseconds(meta.lastModifiedAtMillis!!)
val lastModifiedAt = (lastModifiedInstant - windowsEpoch).inWholeNanoseconds / 100L
this somehow results in a date around year 1404
(so about 600 years off)
this works though
val lastModifiedAt = (lastModifiedInstant - windowsEpoch).inWholeMicroseconds * 10L
my best guess is that somewhere it goes past max long when i get the time in nanoseconds, but its fine with microsecondsilya.gorbunov
06/23/2021, 4:08 PMinWholeNanoseconds
can represent duration range of about +-292 years. However for a greater duration, the value of inWholeNanoseconds
doesn't overflow to negative but rather saturates at the maximum value, i.e. at 2^31-1 nanoseconds.ilya.gorbunov
06/23/2021, 4:17 PMinWholeMicroseconds
is ok, if you're fine with loosing some precision, because such big Duration values can only represent values accurate to milliseconds.
If you want to get the maximum precision, you can use instantNow.minus(instantEpoch, DateTimeUnit.TimeBased)
or instantEpoch.until(instantNow, DateTimeUnit.TimeBased)
functions, and pass there DateTimeUnit.NANOSECOND * 100
as a date time unit to get the difference between these two instants expressed in 100ns intervals, which I suppose is what you need.Nikky
06/23/2021, 5:36 PMilya.gorbunov
06/23/2021, 5:44 PMmeta.lastModifiedAtMillis
is in milliseconds too, so it should be fine to use Duration
to store even that big difference values at millisecond precision and then convert them to 100ns-interval values.