libnx  v4.7.0
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.
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  */
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  */
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 
Service object structure.
Definition: service.h:14
Definition: time.h:39
s32 offset
Seconds relative to UTC for this timezone.
Definition: time.h:44
u32 DST
0 = no DST, 1 = DST.
Definition: time.h:43
u32 yday
0-based day-of-year.
Definition: time.h:41
u32 wday
0-based day-of-week.
Definition: time.h:40
Definition: time.h:29
Definition: time.h:51
Definition: time.h:55
Uuid source_id
An ID representing the clock source.
Definition: time.h:57
s64 time_point
Monotonic count in seconds.
Definition: time.h:56
Definition: time.h:65
Definition: time.h:47
Definition: types.h:48
TimeType
Time clock type.
Definition: time.h:22
Result timeGetStandardSteadyClockTimePoint(TimeSteadyClockTimePoint *out)
Gets the timepoint for the standard steady clock.
Service * timeGetServiceSession_TimeZoneService(void)
Gets the Service object for ITimeZoneService.
Result timeGetStandardSteadyClockInternalOffset(s64 *out)
[3.0.0+] Gets the internal offset for the standard steady clock.
void timeExit(void)
Exit time. Used automatically during app startup.
void * timeGetSharedmemAddr(void)
[6.0.0+] Gets the address of the SharedMemory.
TimeServiceType
Values for __nx_time_service_type.
Definition: time.h:13
@ TimeServiceType_Repair
Initializes time:r. Only available with [9.0.0+].
Definition: time.h:17
@ TimeServiceType_SystemUser
Initializes time:su. Only available with [9.0.0+].
Definition: time.h:18
@ TimeServiceType_System
Initializes time:s.
Definition: time.h:16
@ TimeServiceType_User
Default. Initializes time:u.
Definition: time.h:14
@ TimeServiceType_Menu
Initializes time:a.
Definition: time.h:15
Service * timeGetServiceSession_SteadyClock(void)
Gets the Service object for ISteadyClock.
Result timeGetCurrentTime(TimeType type, u64 *timestamp)
Gets the time for the specified clock.
Service * timeGetServiceSession(void)
Gets the Service object for the actual time service session.
Service * timeGetServiceSession_SystemClock(TimeType type)
Gets the Service object for ISystemClock with the specified TimeType. This will return NULL when the ...
Result timeInitialize(void)
Initialize time. Used automatically during app startup.
Result timeSetCurrentTime(TimeType type, u64 timestamp)
Sets the time for the specified clock.
int64_t s64
64-bit signed integer.
Definition: types.h:28
uint64_t u64
64-bit unsigned integer.
Definition: types.h:22
uint8_t u8
8-bit unsigned integer.
Definition: types.h:19
uint16_t u16
16-bit unsigned integer.
Definition: types.h:20
u32 Result
Function error code result type.
Definition: types.h:44
int32_t s32
32-bit signed integer.
Definition: types.h:27
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21