| ... | @@ -228,11 +228,17 @@ pub const DateTime = struct { | ... | @@ -228,11 +228,17 @@ pub const DateTime = struct { |
| 228 | .SSS => try writer.print("{:0>3}", .{self.ms}), | 228 | .SSS => try writer.print("{:0>3}", .{self.ms}), |
| 229 | .MM => try writer.print("{:0>2}", .{self.months + 1}), | 229 | .MM => try writer.print("{:0>2}", .{self.months + 1}), |
| 230 | .z => try writer.writeAll(@tagName(self.timezone)), | 230 | .z => try writer.writeAll(@tagName(self.timezone)), |
| | 231 | .M => try writer.print("{}", .{self.months + 1}), |
| | 232 | .Mo => try printOrdinal(writer, self.months + 1), |
| 231 | | 233 | |
| 232 | .MMM => { | 234 | .MMM => { |
| 233 | const names = [_]string{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; | 235 | const names = [_]string{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; |
| 234 | try writer.writeAll(names[self.months]); | 236 | try writer.writeAll(names[self.months]); |
| 235 | }, | 237 | }, |
| | 238 | .MMMM => try printLongName(writer, self.months, &[_]string{ |
| | 239 | "January", "February", "March", "April", "May", "June", |
| | 240 | "July", "August", "September", "October", "November", "December", |
| | 241 | }), |
| 236 | | 242 | |
| 237 | else => @compileError("'" ++ @tagName(tag) ++ "' not currently supported"), | 243 | else => @compileError("'" ++ @tagName(tag) ++ "' not currently supported"), |
| 238 | } | 244 | } |
| ... | @@ -361,3 +367,17 @@ pub const WeekDay = enum { | ... | @@ -361,3 +367,17 @@ pub const WeekDay = enum { |
| 361 | }; | 367 | }; |
| 362 | } | 368 | } |
| 363 | }; | 369 | }; |
| | 370 | |
| | 371 | fn printOrdinal(writer: anytype, num: u16) !void { |
| | 372 | try writer.print("{}", .{num}); |
| | 373 | try writer.writeAll(switch (num) { |
| | 374 | 1 => "st", |
| | 375 | 2 => "nd", |
| | 376 | 3 => "rd", |
| | 377 | else => "th", |
| | 378 | }); |
| | 379 | } |
| | 380 | |
| | 381 | fn printLongName(writer: anytype, index: u16, names: []const string) !void { |
| | 382 | try writer.writeAll(names[index]); |
| | 383 | } |