Switch dates from i128 to u64

I was making them unnecessarily large by accidentally storing them as microseconds instead of milliseconds. Might be able to get away with seconds in the future
This commit is contained in:
mitteneer 2025-04-28 21:37:08 -04:00
parent 65136a44d6
commit cb89a3e6f3
5 changed files with 7 additions and 7 deletions

View file

@ -17,8 +17,8 @@
// internet connectivity. // internet connectivity.
.dependencies = .{ .dependencies = .{
.jetzig = .{ .jetzig = .{
.url = "https://github.com/jetzig-framework/jetzig/archive/86d82026ab574d4e5c3c6cc3817dda84b510001a.tar.gz", .url = "https://github.com/jetzig-framework/jetzig/archive/1feb18fb74e626fe068ec67532318640a9cb83be.tar.gz",
.hash = "jetzig-0.0.0-IpAgLTkzDwDKmsY9MqM41EHDXWGkViiECa0lzV8xl17x", .hash = "jetzig-0.0.0-IpAgLfMzDwDyAqZ05btcLDd9dfE_bxUbfOI_Wx7a19ed",
}, },
.zeit = .{ .zeit = .{
.url = "https://github.com/rockorager/zeit/archive/refs/heads/main.tar.gz", .url = "https://github.com/rockorager/zeit/archive/refs/heads/main.tar.gz",

View file

@ -33,7 +33,7 @@ pub fn run(allocator: std.mem.Allocator, params: *jetzig.data.Value, env: jetzig
.artists_track = track_artist_name_buffer, .artists_track = track_artist_name_buffer,
.album = item.getT(.string, "album") orelse "", .album = item.getT(.string, "album") orelse "",
.artists_album = album_artist_name_buffer, .artists_album = album_artist_name_buffer,
.date = @as(u64, @bitCast(@as(i64, @truncate(item.getT(.integer, "date").? * 1000)))), .date = @as(u64, @bitCast(@as(i64, @truncate(item.getT(.integer, "date").?)))),
}; };
var id_prehash = std.ArrayList(u8).init(allocator); var id_prehash = std.ArrayList(u8).init(allocator);

View file

@ -35,7 +35,7 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
try scrobble_view.put("album_name", scrobble.album_name); try scrobble_view.put("album_name", scrobble.album_name);
try scrobble_view.put("album_id", scrobble.album_id); try scrobble_view.put("album_id", scrobble.album_id);
var date = std.ArrayList(u8).init(request.allocator); var date = std.ArrayList(u8).init(request.allocator);
try (try zeit.instant(.{ .source = .{ .unix_timestamp = @divFloor(scrobble.date, 1_000_000) } })).time().strftime(date.writer(), "%d %b %Y, %H:%M"); try (try zeit.instant(.{ .source = .{ .unix_timestamp = @divFloor(scrobble.date, 1_000) } })).time().strftime(date.writer(), "%d %b %Y, %H:%M");
try scrobble_view.put("date", date.items); try scrobble_view.put("date", date.items);
} }

View file

@ -111,7 +111,7 @@ pub fn post(request: *jetzig.Request) !jetzig.View {
.track = scrobble.master_metadata_track_name.?, .track = scrobble.master_metadata_track_name.?,
.album = scrobble.master_metadata_album_album_name.?, .album = scrobble.master_metadata_album_album_name.?,
.artist = scrobble.master_metadata_album_artist_name.?, .artist = scrobble.master_metadata_album_artist_name.?,
.date = (try zeit.instant(.{ .source = .{ .iso8601 = scrobble.ts } })).unixTimestamp() * 1000, .date = @as(u64, @bitCast((try zeit.instant(.{ .source = .{ .iso8601 = scrobble.ts } })).unixTimestamp() * 1000)),
}; };
const formatted_scrobble = if (rule_list) |rl| const formatted_scrobble = if (rule_list) |rl|

View file

@ -2,7 +2,7 @@ pub const ImportedScrobble = struct {
track: []const u8, track: []const u8,
artist: []const u8, artist: []const u8,
album: []const u8 = "", album: []const u8 = "",
date: i128, date: u64,
}; };
pub const Scrobble = struct { pub const Scrobble = struct {
@ -10,7 +10,7 @@ pub const Scrobble = struct {
artists_track: []const []const u8, artists_track: []const []const u8,
album: []const u8 = "", album: []const u8 = "",
artists_album: []const []const u8, artists_album: []const []const u8,
date: i128, date: u64,
}; };
// From lastfmstats.com // From lastfmstats.com