libnx  v4.2.2
time.h
Go to the documentation of this file.
1 /**
2  * @file time.h
3  * @brief Time services IPC wrapper.
4  * @author yellows8
5  * @copyright libnx Authors
6  */
7 #pragma once
8 
9 #include "../types.h"
10 #include "../sf/service.h"
11 
12 /// Values for __nx_time_service_type.
13 typedef enum {
14  TimeServiceType_User = 0, ///< Default. Initializes time:u.
15  TimeServiceType_Menu = 1, ///< Initializes time:a
16  TimeServiceType_System = 2, ///< Initializes time:s.
17  TimeServiceType_Repair = 3, ///< Initializes time:r. Only available with [9.0.0+].
18  TimeServiceType_SystemUser = 4, ///< Initializes time:su. Only available with [9.0.0+].
20 
21 /// Time clock type.
22 typedef enum {
23  TimeType_UserSystemClock,
24  TimeType_NetworkSystemClock,
25  TimeType_LocalSystemClock,
26  TimeType_Default = TimeType_UserSystemClock,
27 } TimeType;
28 
29 typedef struct {
30  u16 year;
31  u8 month;
32  u8 day;
33  u8 hour;
34  u8 minute;
35  u8 second;
36  u8 pad;
38 
39 typedef struct {
40  u32 wday; ///< 0-based day-of-week.
41  u32 yday; ///< 0-based day-of-year.
42  char timezoneName[8]; ///< Timezone name string.
43  u32 DST; ///< 0 = no DST, 1 = DST.
44  s32 offset; ///< Seconds relative to UTC for this timezone.
46 
47 typedef struct {
48  u8 data[0x4000];
49 } TimeZoneRule;
50 
51 typedef struct {
52  char name[0x24];
54 
55 typedef struct {
56  s64 time_point; ///< Monotonic count in seconds.
57  Uuid source_id; ///< An ID representing the clock source.
59 
60 typedef struct {
61  s64 base_time;
62  Uuid source_id;
64 
65 typedef struct {
66  s64 offset;
67  TimeSteadyClockTimePoint timestamp;
69 
70 /// Initialize time. Used automatically during app startup.
72 
73 /// Exit time. Used automatically during app startup.
74 void timeExit(void);
75 
76 /// Gets the Service object for the actual time service session.
78 
79 /// Gets the Service object for ISystemClock with the specified \ref TimeType. This will return NULL when the type is invalid.
81 
82 /// Gets the Service object for ISteadyClock.
84 
85 /// Gets the Service object for ITimeZoneService.
87 
88 /// [6.0.0+] Gets the address of the SharedMemory.
89 void* timeGetSharedmemAddr(void);
90 
91 /**
92  * @brief Gets the timepoint for the standard steady clock.
93  * @param[out] out Output timepoint (see \ref TimeSteadyClockTimePoint)
94  * @remark The standard steady clock counts time since the RTC was configured (usually this happens during manufacturing).
95  * @return Result code.
96  */
98 
99 /**
100  * @brief [3.0.0+] Gets the internal offset for the standard steady clock.
101  * @param[out] out Output internal offset.
102  * @return Result code.
103  */
105 
106 /**
107  * @brief Gets the time for the specified clock.
108  * @param[in] type Clock to use.
109  * @param[out] timestamp POSIX UTC timestamp.
110  * @return Result code.
111  */
112 Result timeGetCurrentTime(TimeType type, u64 *timestamp);
113 
114 /**
115  * @brief Sets the time for the specified clock.
116  * @param[in] type Clock to use.
117  * @param[in] timestamp POSIX UTC timestamp.
118  * @return Result code.
119  */
120 Result timeSetCurrentTime(TimeType type, u64 timestamp);
121 
122 Result timeGetDeviceLocationName(TimeLocationName *name);
123 Result timeSetDeviceLocationName(const TimeLocationName *name);
124 Result timeGetTotalLocationNameCount(s32 *total_location_name_count);
125 Result timeLoadLocationNameList(s32 index, TimeLocationName *location_name_array, s32 location_name_max, s32 *location_name_count);
126 
127 Result timeLoadTimeZoneRule(const TimeLocationName *name, TimeZoneRule *rule);
128 
129 Result timeToCalendarTime(const TimeZoneRule *rule, u64 timestamp, TimeCalendarTime *caltime, TimeCalendarAdditionalInfo *info);
130 Result timeToCalendarTimeWithMyRule(u64 timestamp, TimeCalendarTime *caltime, TimeCalendarAdditionalInfo *info);
131 Result timeToPosixTime(const TimeZoneRule *rule, const TimeCalendarTime *caltime, u64 *timestamp_list, s32 timestamp_list_count, s32 *timestamp_count);
132 Result timeToPosixTimeWithMyRule(const TimeCalendarTime *caltime, u64 *timestamp_list, s32 timestamp_list_count, s32 *timestamp_count);
133 
s64
int64_t s64
64-bit signed integer.
Definition: types.h:28
TimeSystemClockContext
Definition: time.h:65
TimeStandardSteadyClockTimePointType
Definition: time.h:60
TimeCalendarTime
Definition: time.h:29
TimeLocationName
Definition: time.h:51
TimeSteadyClockTimePoint
Definition: time.h:55
TimeCalendarAdditionalInfo::yday
u32 yday
0-based day-of-year.
Definition: time.h:41
timeSetCurrentTime
Result timeSetCurrentTime(TimeType type, u64 timestamp)
Sets the time for the specified clock.
u8
uint8_t u8
8-bit unsigned integer.
Definition: types.h:19
TimeCalendarAdditionalInfo::DST
u32 DST
0 = no DST, 1 = DST.
Definition: time.h:43
TimeType
TimeType
Time clock type.
Definition: time.h:22
TimeServiceType_System
@ TimeServiceType_System
Initializes time:s.
Definition: time.h:16
TimeServiceType_Menu
@ TimeServiceType_Menu
Initializes time:a.
Definition: time.h:15
timeGetStandardSteadyClockInternalOffset
Result timeGetStandardSteadyClockInternalOffset(s64 *out)
[3.0.0+] Gets the internal offset for the standard steady clock.
s32
int32_t s32
32-bit signed integer.
Definition: types.h:27
timeGetCurrentTime
Result timeGetCurrentTime(TimeType type, u64 *timestamp)
Gets the time for the specified clock.
timeInitialize
Result timeInitialize(void)
Initialize time. Used automatically during app startup.
u32
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21
TimeServiceType_SystemUser
@ TimeServiceType_SystemUser
Initializes time:su. Only available with [9.0.0+].
Definition: time.h:18
timeGetServiceSession_SystemClock
Service * timeGetServiceSession_SystemClock(TimeType type)
Gets the Service object for ISystemClock with the specified TimeType. This will return NULL when the ...
u64
uint64_t u64
64-bit unsigned integer.
Definition: types.h:22
Result
u32 Result
Function error code result type.
Definition: types.h:44
TimeCalendarAdditionalInfo::offset
s32 offset
Seconds relative to UTC for this timezone.
Definition: time.h:44
TimeCalendarAdditionalInfo::wday
u32 wday
0-based day-of-week.
Definition: time.h:40
Uuid
Definition: types.h:48
TimeCalendarAdditionalInfo
Definition: time.h:39
TimeServiceType_User
@ TimeServiceType_User
Default. Initializes time:u.
Definition: time.h:14
TimeServiceType_Repair
@ TimeServiceType_Repair
Initializes time:r. Only available with [9.0.0+].
Definition: time.h:17
timeExit
void timeExit(void)
Exit time. Used automatically during app startup.
timeGetServiceSession
Service * timeGetServiceSession(void)
Gets the Service object for the actual time service session.
TimeZoneRule
Definition: time.h:47
Service
Service object structure.
Definition: service.h:13
timeGetStandardSteadyClockTimePoint
Result timeGetStandardSteadyClockTimePoint(TimeSteadyClockTimePoint *out)
Gets the timepoint for the standard steady clock.
timeGetSharedmemAddr
void * timeGetSharedmemAddr(void)
[6.0.0+] Gets the address of the SharedMemory.
TimeServiceType
TimeServiceType
Values for __nx_time_service_type.
Definition: time.h:13
timeGetServiceSession_TimeZoneService
Service * timeGetServiceSession_TimeZoneService(void)
Gets the Service object for ITimeZoneService.
TimeSteadyClockTimePoint::source_id
Uuid source_id
An ID representing the clock source.
Definition: time.h:57
timeGetServiceSession_SteadyClock
Service * timeGetServiceSession_SteadyClock(void)
Gets the Service object for ISteadyClock.
u16
uint16_t u16
16-bit unsigned integer.
Definition: types.h:20
TimeSteadyClockTimePoint::time_point
s64 time_point
Monotonic count in seconds.
Definition: time.h:56