1/**
2 * @file time.h
3 * @brief Time implementation.
4 */
5
6#pragma once
7
8#include <nn/types.h>
9
10namespace nn {
11class TimeSpan {
12public:
13 u64 nanoseconds;
14
15 static TimeSpan FromNanoSeconds(u64 nanoSeconds) {
16 TimeSpan ret;
17 ret.nanoseconds = nanoSeconds;
18 return ret;
19 }
20
21 static TimeSpan FromSeconds(u64 seconds) {
22 return FromNanoSeconds(nanoSeconds: seconds * 1000 * 1000 * 1000);
23 }
24 static TimeSpan FromMinutes(u64 minutes) {
25 return FromNanoSeconds(nanoSeconds: minutes * 1000 * 1000 * 1000 * 60);
26 }
27 static TimeSpan FromHours(u64 hours) {
28 return FromNanoSeconds(nanoSeconds: hours * 1000 * 1000 * 1000 * 60 * 60);
29 }
30 static TimeSpan FromDays(u64 days) {
31 return FromNanoSeconds(nanoSeconds: days * 1000 * 1000 * 1000 * 60 * 60 * 24);
32 }
33};
34
35namespace time {
36
37Result Initialize();
38bool IsInitialized();
39
40struct CalendarTime {
41 s16 year;
42 s8 month;
43 s8 day;
44 s8 hour;
45 s8 minute;
46 s8 second;
47};
48
49enum DayOfTheWeek { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };
50
51struct TimeZone {
52 char standardTimeName[0x8];
53 bool _9; // daylight savings or something?
54 s32 utcOffset; // in seconds
55};
56
57struct CalendarAdditionalInfo {
58 nn::time::DayOfTheWeek dayOfTheWeek;
59 s32 dayofYear;
60 nn::time::TimeZone timeZone;
61};
62
63struct PosixTime {
64 u64 time;
65};
66
67class StandardUserSystemClock {
68public:
69 static Result GetCurrentTime(nn::time::PosixTime*);
70};
71
72struct TimeZoneRule; // shrug
73
74Result ToCalendarTime(nn::time::CalendarTime*, nn::time::CalendarAdditionalInfo*,
75 nn::time::PosixTime const&);
76Result ToCalendarTime(nn::time::CalendarTime*, nn::time::CalendarAdditionalInfo*,
77 nn::time::PosixTime const&, nn::time::TimeZoneRule const&);
78Result ToPosixTime(int*, PosixTime*, int, const CalendarTime&);
79CalendarTime ToCalendarTimeInUtc(const PosixTime&);
80PosixTime ToPosixTimeFromUtc(const CalendarTime&);
81} // namespace time
82} // namespace nn
83