summaryrefslogtreecommitdiff
path: root/include/gammu-datetime.h
blob: 5fd4860293f67e2043e8c9550c626730f093f8bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/**
 * \file gammu-datetime.h
 * \author Michal Čihař
 *
 * Date and time manipulations.
 */
#ifndef __gammu_datetime_h
#define __gammu_datetime_h

/**
 * \defgroup DateTime Date and time
 * Date and time handling.
 */

#ifdef	__cplusplus
extern "C" {
#endif

#include <time.h>
#include <gammu-error.h>
#include <gammu-statemachine.h>

/**
 * Structure used for saving date and time
 *
 * \ingroup DateTime
 */
typedef struct {
	/**
	 * The difference between local time and GMT in seconds
	 */
	int Timezone;

	/**
	 * Seconds.
	 */
	int Second;
	/**
	 * Minutes.
	 */
	int Minute;
	/**
	 * Hours.
	 */
	int Hour;

	/**
	 * Days.
	 */
	int Day;
	/**
	 * January = 1, February = 2, etc.
	 */
	int Month;
	/**
	 * Complete year number. Not 03, but 2003
	 */
	int Year;
} GSM_DateTime;

/**
 * Structure used for saving relative date and time
 *
 * \ingroup DateTime
 */
typedef struct {
	/**
	 * The difference of timezones in seconds
	 */
	int Timezone;

	/**
	 * Seconds diff.
	 */
	int Second;
	/**
	 * Minutes diff.
	 */
	int Minute;
	/**
	 * Hours diff.
	 */
	int Hour;

	/**
	 * Days diff.
	 */
	int Day;
	/**
	 * Months diff.
	 */
	int Month;
	/**
	 * Years diff.
	 */
	int Year;
} GSM_DeltaTime;

/**
 * Returns string for current day of week.
 *
 * \param year Year.
 * \param month Month.
 * \param day Day.
 *
 * \return Pointer to static buffer containing day of week string.
 *
 * \ingroup DateTime
 */
char *DayOfWeek(unsigned int year, unsigned int month, unsigned int day);

/**
 * Returns current timestamp.
 *
 * \param Date Storage for date time structure.
 *
 * \ingroup DateTime
 */
void GSM_GetCurrentDateTime(GSM_DateTime * Date);

/**
 * Converts \ref GSM_DateTime to time_t.
 *
 * \param DT Input timestamp.
 *
 * \return time_t value.
 *
 * \ingroup DateTime
 */
time_t Fill_Time_T(GSM_DateTime DT);

/**
 * Returns the local timezone offset in seconds.
 * For example 7200 for CEST.
 *
 * \return Timezone offset seconds.
 *
 * \ingroup DateTime
 */
int GSM_GetLocalTimezoneOffset(void);

/**
 * Converts time_t to gammu \ref GSM_DateTime structure.
 *
 * \param Date Storage for date.
 * \param timet Input date.
 *
 * \ingroup DateTime
 */
void Fill_GSM_DateTime(GSM_DateTime * Date, time_t timet);

/**
 * Converts string (seconds since epoch) to gammu \ref GSM_DateTime structure.
 *
 * \param Date Storage for date.
 * \param str Input date.
 *
 * \ingroup DateTime
 */
void GSM_DateTimeFromTimestamp(GSM_DateTime *Date, const char *str);

/**
 * Converts gammu \ref GSM_DateTime structure to string (seconds since epoch).
 *
 * \param Date Date.
 * \param str Strorage for string.
 *
 * \ingroup DateTime
 */
void GSM_DateTimeToTimestamp(GSM_DateTime *Date, char *str);

/**
 * Converts timestamp to string according to OS settings.
 *
 * \param dt Input timestamp.
 * \param TimeZone Whether to include time zone.
 *
 * \return Pointer to static buffer containing string.
 *
 * \ingroup DateTime
 */
char *OSDateTime(GSM_DateTime dt, gboolean TimeZone);

/**
 * Converts date from timestamp to string according to OS settings.
 *
 * \param dt Input timestamp.
 *
 * \return Pointer to static buffer containing string.
 *
 * \ingroup DateTime
 */
char *OSDate(GSM_DateTime dt);

/**
 * Checks whether date is valid. This does not check time, see
 * \ref CheckTime for this.
 *
 * \param date Structure where to check date.
 *
 * \return True if date is correct.
 *
 * \ingroup DateTime
 */
gboolean CheckDate(GSM_DateTime * date);

/**
 * Checks whether time is valid. This does not check date, see
 * \ref CheckDate for this.
 *
 * \param date Structure where to check time.
 *
 * \return True if time is correct.
 *
 * \ingroup DateTime
 */
gboolean CheckTime(GSM_DateTime * date);

/**
 * Reads date and time from phone.
 *
 * \param s State machine pointer.
 * \param date_time Storage for date.
 *
 * \return Error code
 *
 * \ingroup Category
 */
GSM_Error GSM_GetDateTime(GSM_StateMachine * s, GSM_DateTime * date_time);

/**
 * Sets date and time in phone.
 *
 * \param s State machine pointer.
 * \param date_time Date to set.
 *
 * \return Error code
 *
 * \ingroup Category
 */
GSM_Error GSM_SetDateTime(GSM_StateMachine * s, GSM_DateTime * date_time);
#ifdef	__cplusplus
}
#endif
#endif

/* Editor configuration
 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72:
 */