Fix date formatting in scrobble view
This commit is contained in:
parent
d6a638bf27
commit
1734e6a4bb
2 changed files with 4 additions and 4 deletions
|
|
@ -3,6 +3,7 @@ const jetzig = @import("jetzig");
|
||||||
const zeit = @import("zeit");
|
const zeit = @import("zeit");
|
||||||
const TableRow = @import("../../types.zig").TableRow;
|
const TableRow = @import("../../types.zig").TableRow;
|
||||||
const HyperlinkData = @import("../../types.zig").HyperlinkData;
|
const HyperlinkData = @import("../../types.zig").HyperlinkData;
|
||||||
|
const Utils = @import("../../date_fmt.zig");
|
||||||
|
|
||||||
pub fn index(request: *jetzig.Request) !jetzig.View {
|
pub fn index(request: *jetzig.Request) !jetzig.View {
|
||||||
var root = try request.data(.object);
|
var root = try request.data(.object);
|
||||||
|
|
@ -35,8 +36,7 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
|
||||||
try artistlist.append(.{ .name = scrobble.artist_name, .id = scrobble.artist_id });
|
try artistlist.append(.{ .name = scrobble.artist_name, .id = scrobble.artist_id });
|
||||||
continue :blk;
|
continue :blk;
|
||||||
} else {
|
} else {
|
||||||
var date = std.ArrayList(u8).init(request.allocator);
|
const date = try Utils.dateFmt(request.allocator, scrobble.date);
|
||||||
try (try zeit.instant(.{ .source = .{ .unix_timestamp = @divFloor(scrobble.date, 1_000) } })).time().strftime(date.writer(), "%d %b %Y, %H:%M");
|
|
||||||
|
|
||||||
try artistlist.append(.{ .name = scrobble.artist_name, .id = scrobble.artist_id });
|
try artistlist.append(.{ .name = scrobble.artist_name, .id = scrobble.artist_id });
|
||||||
|
|
||||||
|
|
@ -44,7 +44,7 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
|
||||||
.song = .{ .name = scrobble.song_name, .id = scrobble.song_id },
|
.song = .{ .name = scrobble.song_name, .id = scrobble.song_id },
|
||||||
.album = .{ .name = scrobble.album_name, .id = scrobble.album_id },
|
.album = .{ .name = scrobble.album_name, .id = scrobble.album_id },
|
||||||
.artistlist = try artistlist.toOwnedSlice(),
|
.artistlist = try artistlist.toOwnedSlice(),
|
||||||
.date = date.items,
|
.date = date,
|
||||||
};
|
};
|
||||||
|
|
||||||
try scrobbles_view.append(row);
|
try scrobbles_view.append(row);
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ pub fn post(request: *jetzig.Request) !jetzig.View {
|
||||||
if (max_pages != null and page > max_pages.?) break;
|
if (max_pages != null and page > max_pages.?) break;
|
||||||
const query: []const u8 = try std.fmt.allocPrint(request.allocator, "https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user={s}&api_key=b0c410a48a6078a651e0832699e3cd41&from={}&to={}&page={}&limit=1000&format=json", .{ username, earliest_timestamp, latest_timestamp, page });
|
const query: []const u8 = try std.fmt.allocPrint(request.allocator, "https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user={s}&api_key=b0c410a48a6078a651e0832699e3cd41&from={}&to={}&page={}&limit=1000&format=json", .{ username, earliest_timestamp, latest_timestamp, page });
|
||||||
const r = try client.fetch(.{ .response_storage = .{ .dynamic = &lastfm_response_buffer }, .location = .{ .url = query }, .method = .GET, .headers = .{ .user_agent = .{ .override = user_agent } } });
|
const r = try client.fetch(.{ .response_storage = .{ .dynamic = &lastfm_response_buffer }, .location = .{ .url = query }, .method = .GET, .headers = .{ .user_agent = .{ .override = user_agent } } });
|
||||||
std.log.debug("{}", .{r});
|
std.log.debug("{}: {}", .{ page, r });
|
||||||
const response_string = try lastfm_response_buffer.toOwnedSlice();
|
const response_string = try lastfm_response_buffer.toOwnedSlice();
|
||||||
const parsed_lastfm_response = try std.json.parseFromSliceLeaky(Data.LastFMWeb, request.allocator, response_string, .{ .ignore_unknown_fields = true });
|
const parsed_lastfm_response = try std.json.parseFromSliceLeaky(Data.LastFMWeb, request.allocator, response_string, .{ .ignore_unknown_fields = true });
|
||||||
//const current_page = try std.fmt.parseInt(usize, parsed_lastfm_response.recenttracks.@"@attr".page, 10);
|
//const current_page = try std.fmt.parseInt(usize, parsed_lastfm_response.recenttracks.@"@attr".page, 10);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue