Skip to content

Instantly share code, notes, and snippets.

@marler8997
Last active November 12, 2024 18:14
Show Gist options
  • Save marler8997/d37eaf26633fea41d4efcf813ad64b50 to your computer and use it in GitHub Desktop.
Save marler8997/d37eaf26633fea41d4efcf813ad64b50 to your computer and use it in GitHub Desktop.
fn hns_from_filetime(filetime: win32.FILETIME) u64 {
return @as(u64, filetime.dwLowDateTime) |
(@as(u64, filetime.dwHighDateTime) << 32);
}
const TimeFmt = struct {
hns: u64,
pub fn format(
self: TimeFmt,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
writer: anytype,
) !void {
_ = fmt;
_ = options;
const hns_per_s = std.time.ns_per_s / 100;
const epoch_seconds = std.time.epoch.EpochSeconds{
.secs = self.hns / hns_per_s - (-std.time.epoch.windows),
};
const sub_secs = self.hns % hns_per_s;
const yd = epoch_seconds.getEpochDay().calculateYearDay();
const md = yd.calculateMonthDay();
const ds = epoch_seconds.getDaySeconds();
try writer.print("{}-{}-{}T{:0>2}:{:0>2}:{:0>2}.{}", .{
yd.year,
@intFromEnum(md.month),
md.day_index + 1,
ds.getHoursIntoDay(),
ds.getMinutesIntoHour(),
ds.getSecondsIntoMinute(),
sub_secs,
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment