Skip to content

Commit b8406b0

Browse files
author
wooster0
committed
std.time.epoch: deprecate previously renamed structures
1 parent 00163f1 commit b8406b0

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

lib/std/time/epoch.zig

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,50 @@ pub const Seconds = struct {
191191
}
192192
};
193193

194+
/// Deprecated: use `YearAndDays`.
195+
pub const YearAndDay = struct {
196+
year: Year,
197+
day: u9,
198+
pub fn calculateMonthDay(self: YearAndDay) MonthAndDay {
199+
var month: Month = .jan;
200+
var days_left = self.day;
201+
while (true) {
202+
const days_in_month = getDaysInMonth(self.year, month);
203+
if (days_left < days_in_month)
204+
break;
205+
days_left -= days_in_month;
206+
month = @as(Month, @enumFromInt(@intFromEnum(month) + 1));
207+
}
208+
return .{ .month = month, .day_index = @as(u5, @intCast(days_left)) };
209+
}
210+
};
211+
/// Deprecated: use `Days`.
212+
pub const EpochDay = struct {
213+
day: u47,
214+
pub fn calculateYearDay(self: EpochDay) YearAndDay {
215+
var year_day = self.day;
216+
var year: Year = epoch_year;
217+
while (true) {
218+
const year_size = getDaysInYear(year);
219+
if (year_day < year_size)
220+
break;
221+
year_day -= year_size;
222+
year += 1;
223+
}
224+
return .{ .year = year, .day = @as(u9, @intCast(year_day)) };
225+
}
226+
};
227+
/// Deprecated: use `Seconds`.
228+
pub const EpochSeconds = struct {
229+
secs: u64,
230+
pub fn getEpochDay(self: EpochSeconds) EpochDay {
231+
return EpochDay{ .day = @as(u47, @intCast(@divTrunc(self.secs, secs_per_day))) };
232+
}
233+
pub fn getDaySeconds(self: EpochSeconds) DaySeconds {
234+
return DaySeconds{ .secs = math.comptimeMod(self.secs, secs_per_day) };
235+
}
236+
};
237+
194238
fn testDecode(secs: u64, expected_year_day: YearAndDays, expected_month_day: MonthAndDay, expected_day_seconds: struct {
195239
/// 0 to 23.
196240
hours_into_day: u5,

0 commit comments

Comments
 (0)