Merge lp:~libzeitgeist-developers/libzeitgeist/timestamps into lp:libzeitgeist
- timestamps
- Merge into trunk
Proposed by
Mikkel Kamstrup Erlandsen
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 129 | ||||
Proposed branch: | lp:~libzeitgeist-developers/libzeitgeist/timestamps | ||||
Merge into: | lp:libzeitgeist | ||||
Diff against target: |
822 lines (+564/-45) 16 files modified
bindings/zeitgeist-1.0-custom.vala (+45/-5) bindings/zeitgeist-1.0.gi (+55/-0) bindings/zeitgeist-1.0.metadata (+4/-0) bindings/zeitgeist-1.0.namespace (+1/-0) bindings/zeitgeist-1.0.vapi (+31/-4) doc/reference/zeitgeist-1.0-docs.sgml (+1/-0) doc/reference/zeitgeist-1.0-sections.txt (+21/-4) src/Makefile.am (+3/-0) src/zeitgeist-event.c (+2/-2) src/zeitgeist-timerange.c (+6/-6) src/zeitgeist-timerange.h (+0/-24) src/zeitgeist-timestamp.c (+194/-0) src/zeitgeist-timestamp.h (+100/-0) src/zeitgeist.h (+1/-0) tests/Makefile.am (+4/-0) tests/test-timestamp.c (+96/-0) |
||||
To merge this branch: | bzr merge lp:~libzeitgeist-developers/libzeitgeist/timestamps | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
LibZeitgeist Developers | Pending | ||
Review via email: mp+27822@code.launchpad.net |
Commit message
Description of the change
Add a new namespace Zeitgeist.
The following macros have been changed:
- ZEITGEIST_
- ZEITGEIST_
To post a comment you must log in.
- 134. By Mikkel Kamstrup Erlandsen <kamstrup@hardback>
-
Vala: The Zeitgeist.Timestamp namespace should still include zeitgeist.h not zeitgeist-
1.0-custom. h
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'bindings/zeitgeist-1.0-custom.vala' |
2 | --- bindings/zeitgeist-1.0-custom.vala 2010-06-17 08:27:02 +0000 |
3 | +++ bindings/zeitgeist-1.0-custom.vala 2010-06-17 14:14:24 +0000 |
4 | @@ -30,11 +30,51 @@ |
5 | [CCode (cname = "_vala_zeitgeist_result_set_iterator")] |
6 | public ResultSet iterator (); |
7 | } |
8 | - |
9 | - [CCode (cname = "ZEITGEIST_GTIMEVAL_TO_TIMESTAMP")] |
10 | - public static int64 timeval_to_timestamp (GLib.TimeVal time_val); |
11 | - [CCode (cname = "ZEITGEIST_TIMESTAMP_TO_GTIMEVAL")] |
12 | - public static GLib.TimeVal timestamp_to_timeval (int64 timestamp); |
13 | +} |
14 | + |
15 | +namespace Zeitgeist.Timestamp |
16 | +{ |
17 | + [CCode (cname = "ZEITGEIST_TIMESTAMP_SECOND", cheader_filename = "zeitgeist.h")] |
18 | + public int64 SECOND; |
19 | + |
20 | + [CCode (cname = "ZEITGEIST_TIMESTAMP_MINUTE", cheader_filename = "zeitgeist.h")] |
21 | + public int64 MINUTE; |
22 | + |
23 | + [CCode (cname = "ZEITGEIST_TIMESTAMP_HOUR", cheader_filename = "zeitgeist.h")] |
24 | + public int64 HOUR; |
25 | + |
26 | + [CCode (cname = "ZEITGEIST_TIMESTAMP_DAY", cheader_filename = "zeitgeist.h")] |
27 | + public int64 DAY; |
28 | + |
29 | + [CCode (cname = "ZEITGEIST_TIMESTAMP_WEEK", cheader_filename = "zeitgeist.h")] |
30 | + public int64 WEEK; |
31 | + |
32 | + [CCode (cname = "ZEITGEIST_TIMESTAMP_YEAR", cheader_filename = "zeitgeist.h")] |
33 | + public int64 YEAR; |
34 | + |
35 | + [CCode (cname = "zeitgeist_timestamp_for_now", cheader_filename = "zeitgeist.h")] |
36 | + public int64 now (); |
37 | + |
38 | + [CCode (cname = "zeitgeist_timestamp_from_timeval", cheader_filename = "zeitgeist.h")] |
39 | + public int64 from_timeval (GLib.TimeVal tv); |
40 | + |
41 | + [CCode (cname = "zeitgeist_timestamp_to_timeval", cheader_filename = "zeitgeist.h")] |
42 | + public int64 to_timeval (int64 timestamp, out GLib.TimeVal tv); |
43 | + |
44 | + [CCode (cname = "zeitgeist_timestamp_from_iso8601", cheader_filename = "zeitgeist.h")] |
45 | + public int64 from_iso8601 (string datetime); |
46 | + |
47 | + [CCode (cname = "zeitgeist_timestamp_to_iso8601", cheader_filename = "zeitgeist.h")] |
48 | + public string to_iso8601 (int64 timestamp); |
49 | + |
50 | + [CCode (cname = "zeitgeist_timestamp_from_date", cheader_filename = "zeitgeist.h")] |
51 | + public int64 from_date (GLib.Date date); |
52 | + |
53 | + [CCode (cname = "zeitgeist_timestamp_from_dmy", cheader_filename = "zeitgeist.h")] |
54 | + public int64 from_dmy (GLib.DateDay day, GLib.DateMonth month, GLib.DateYear year); |
55 | + |
56 | + [CCode (cname = "zeitgeist_timestamp_to_date", cheader_filename = "zeitgeist.h")] |
57 | + public int64 to_date (int64 timestamp, out GLib.Date date); |
58 | } |
59 | |
60 | // vim:et:ai:cindent:ts=2 sts=2 sw=2: |
61 | |
62 | === modified file 'bindings/zeitgeist-1.0.gi' |
63 | --- bindings/zeitgeist-1.0.gi 2010-06-10 09:43:09 +0000 |
64 | +++ bindings/zeitgeist-1.0.gi 2010-06-17 14:14:24 +0000 |
65 | @@ -34,6 +34,55 @@ |
66 | <parameter name="manifestation_type" type="gchar*"/> |
67 | </parameters> |
68 | </function> |
69 | + <function name="timestamp_for_now" symbol="zeitgeist_timestamp_for_now"> |
70 | + <return-type type="gint64"/> |
71 | + </function> |
72 | + <function name="timestamp_from_date" symbol="zeitgeist_timestamp_from_date"> |
73 | + <return-type type="gint64"/> |
74 | + <parameters> |
75 | + <parameter name="date" type="GDate*"/> |
76 | + </parameters> |
77 | + </function> |
78 | + <function name="timestamp_from_dmy" symbol="zeitgeist_timestamp_from_dmy"> |
79 | + <return-type type="gint64"/> |
80 | + <parameters> |
81 | + <parameter name="day" type="GDateDay"/> |
82 | + <parameter name="month" type="GDateMonth"/> |
83 | + <parameter name="year" type="GDateYear"/> |
84 | + </parameters> |
85 | + </function> |
86 | + <function name="timestamp_from_iso8601" symbol="zeitgeist_timestamp_from_iso8601"> |
87 | + <return-type type="gint64"/> |
88 | + <parameters> |
89 | + <parameter name="datetime" type="gchar*"/> |
90 | + </parameters> |
91 | + </function> |
92 | + <function name="timestamp_from_timeval" symbol="zeitgeist_timestamp_from_timeval"> |
93 | + <return-type type="gint64"/> |
94 | + <parameters> |
95 | + <parameter name="tv" type="GTimeVal*"/> |
96 | + </parameters> |
97 | + </function> |
98 | + <function name="timestamp_to_date" symbol="zeitgeist_timestamp_to_date"> |
99 | + <return-type type="void"/> |
100 | + <parameters> |
101 | + <parameter name="timestamp" type="gint64"/> |
102 | + <parameter name="date" type="GDate*"/> |
103 | + </parameters> |
104 | + </function> |
105 | + <function name="timestamp_to_iso8601" symbol="zeitgeist_timestamp_to_iso8601"> |
106 | + <return-type type="gchar*"/> |
107 | + <parameters> |
108 | + <parameter name="timestamp" type="gint64"/> |
109 | + </parameters> |
110 | + </function> |
111 | + <function name="timestamp_to_timeval" symbol="zeitgeist_timestamp_to_timeval"> |
112 | + <return-type type="void"/> |
113 | + <parameters> |
114 | + <parameter name="timestamp" type="gint64"/> |
115 | + <parameter name="tv" type="GTimeVal*"/> |
116 | + </parameters> |
117 | + </function> |
118 | <enum name="ZeitgeistResultType" type-name="ZeitgeistResultType" get-type="zeitgeist_result_type_get_type"> |
119 | <member name="ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS" value="0"/> |
120 | <member name="ZEITGEIST_RESULT_TYPE_LEAST_RECENT_EVENTS" value="1"/> |
121 | @@ -781,6 +830,12 @@ |
122 | <constant name="ZEITGEIST_NMO_MAILBOX_DATA_OBJECT" type="char*" value="http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#MailboxDataObject"/> |
123 | <constant name="ZEITGEIST_NMO_MESSAGE" type="char*" value="http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#Message"/> |
124 | <constant name="ZEITGEIST_NMO_MIME_ENTITY" type="char*" value="http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#MimeEntity"/> |
125 | + <constant name="ZEITGEIST_TIMESTAMP_DAY" type="int" value="86400000"/> |
126 | + <constant name="ZEITGEIST_TIMESTAMP_HOUR" type="int" value="3600000"/> |
127 | + <constant name="ZEITGEIST_TIMESTAMP_MINUTE" type="int" value="60000"/> |
128 | + <constant name="ZEITGEIST_TIMESTAMP_SECOND" type="int" value="1000"/> |
129 | + <constant name="ZEITGEIST_TIMESTAMP_WEEK" type="int" value="604800000"/> |
130 | + <constant name="ZEITGEIST_TIMESTAMP_YEAR" type="int" value="2147483647"/> |
131 | <constant name="ZEITGEIST_ZG_ACCESS_EVENT" type="char*" value="http://www.zeitgeist-project.com/ontologies/2010/01/27/zg#AccessEvent"/> |
132 | <constant name="ZEITGEIST_ZG_CREATE_EVENT" type="char*" value="http://www.zeitgeist-project.com/ontologies/2010/01/27/zg#CreateEvent"/> |
133 | <constant name="ZEITGEIST_ZG_DELETE_EVENT" type="char*" value="http://www.zeitgeist-project.com/ontologies/2010/01/27/zg#DeleteEvent"/> |
134 | |
135 | === modified file 'bindings/zeitgeist-1.0.metadata' |
136 | --- bindings/zeitgeist-1.0.metadata 2010-06-16 13:18:59 +0000 |
137 | +++ bindings/zeitgeist-1.0.metadata 2010-06-17 14:14:24 +0000 |
138 | @@ -1,4 +1,5 @@ |
139 | Zeitgeist cheader_filename="zeitgeist.h" |
140 | +Zeitgeist.Timestamp cheader_filename="zeitgeist.h" |
141 | zeitgeist_index_search async="1" |
142 | zeitgeist_index_search.event_templates transfer_ownership="1" |
143 | zeitgeist_index_search_finish transfer_ownership="1" |
144 | @@ -34,3 +35,6 @@ |
145 | |
146 | zeitgeist_log_*.cancellable nullable="1" |
147 | zeitgeist_index_*.cancellable nullable="1" |
148 | + |
149 | +zeitgeist_timestamp_* hidden="1" |
150 | +ZEITGEIST_TIMESTAMP_* hidden="1" |
151 | |
152 | === modified file 'bindings/zeitgeist-1.0.namespace' |
153 | --- bindings/zeitgeist-1.0.namespace 2010-04-19 11:11:55 +0000 |
154 | +++ bindings/zeitgeist-1.0.namespace 2010-06-17 14:14:24 +0000 |
155 | @@ -1,1 +1,2 @@ |
156 | Zeitgeist |
157 | +Zeitgeist.Timestamp |
158 | |
159 | === modified file 'bindings/zeitgeist-1.0.vapi' |
160 | --- bindings/zeitgeist-1.0.vapi 2010-06-17 08:27:02 +0000 |
161 | +++ bindings/zeitgeist-1.0.vapi 2010-06-17 14:14:24 +0000 |
162 | @@ -2,6 +2,37 @@ |
163 | |
164 | [CCode (cprefix = "Zeitgeist", lower_case_cprefix = "zeitgeist_")] |
165 | namespace Zeitgeist { |
166 | + [CCode (cprefix = "ZeitgeistTimestamp", lower_case_cprefix = "zeitgeist_timestamp_")] |
167 | + namespace Timestamp { |
168 | + [CCode (cname = "ZEITGEIST_TIMESTAMP_DAY", cheader_filename = "zeitgeist.h")] |
169 | + public static int64 DAY; |
170 | + [CCode (cname = "ZEITGEIST_TIMESTAMP_HOUR", cheader_filename = "zeitgeist.h")] |
171 | + public static int64 HOUR; |
172 | + [CCode (cname = "ZEITGEIST_TIMESTAMP_MINUTE", cheader_filename = "zeitgeist.h")] |
173 | + public static int64 MINUTE; |
174 | + [CCode (cname = "ZEITGEIST_TIMESTAMP_SECOND", cheader_filename = "zeitgeist.h")] |
175 | + public static int64 SECOND; |
176 | + [CCode (cname = "ZEITGEIST_TIMESTAMP_WEEK", cheader_filename = "zeitgeist.h")] |
177 | + public static int64 WEEK; |
178 | + [CCode (cname = "ZEITGEIST_TIMESTAMP_YEAR", cheader_filename = "zeitgeist.h")] |
179 | + public static int64 YEAR; |
180 | + [CCode (cheader_filename = "zeitgeist.h")] |
181 | + public static int64 from_date (GLib.Date date); |
182 | + [CCode (cheader_filename = "zeitgeist.h")] |
183 | + public static int64 from_dmy (GLib.DateDay day, GLib.DateMonth month, GLib.DateYear year); |
184 | + [CCode (cheader_filename = "zeitgeist.h")] |
185 | + public static int64 from_iso8601 (string datetime); |
186 | + [CCode (cheader_filename = "zeitgeist.h")] |
187 | + public static int64 from_timeval (GLib.TimeVal tv); |
188 | + [CCode (cname = "zeitgeist_timestamp_for_now", cheader_filename = "zeitgeist.h")] |
189 | + public static int64 now (); |
190 | + [CCode (cheader_filename = "zeitgeist.h")] |
191 | + public static int64 to_date (int64 timestamp, out GLib.Date date); |
192 | + [CCode (cheader_filename = "zeitgeist.h")] |
193 | + public static string to_iso8601 (int64 timestamp); |
194 | + [CCode (cheader_filename = "zeitgeist.h")] |
195 | + public static int64 to_timeval (int64 timestamp, out GLib.TimeVal tv); |
196 | + } |
197 | [CCode (cheader_filename = "zeitgeist.h")] |
198 | public class Event : GLib.InitiallyUnowned { |
199 | [CCode (has_construct_function = false)] |
200 | @@ -316,8 +347,4 @@ |
201 | public static void register_mimetype_regex (string mimetype_regex, string interpretation_uri); |
202 | [CCode (cheader_filename = "zeitgeist.h")] |
203 | public static void register_uri_scheme (string uri_scheme, string manifestation_type); |
204 | - [CCode (cname = "ZEITGEIST_TIMESTAMP_TO_GTIMEVAL", cheader_filename = "zeitgeist.h")] |
205 | - public static GLib.TimeVal timestamp_to_timeval (int64 timestamp); |
206 | - [CCode (cname = "ZEITGEIST_GTIMEVAL_TO_TIMESTAMP", cheader_filename = "zeitgeist.h")] |
207 | - public static int64 timeval_to_timestamp (GLib.TimeVal time_val); |
208 | } |
209 | |
210 | === modified file 'doc/reference/zeitgeist-1.0-docs.sgml' |
211 | --- doc/reference/zeitgeist-1.0-docs.sgml 2010-06-09 20:38:14 +0000 |
212 | +++ doc/reference/zeitgeist-1.0-docs.sgml 2010-06-17 14:14:24 +0000 |
213 | @@ -22,6 +22,7 @@ |
214 | <chapter> |
215 | <title>Utility Functions</title> |
216 | <xi:include href="xml/zeitgeist-mimetypes.xml"/> |
217 | + <xi:include href="xml/zeitgeist-timestamp.xml"/> |
218 | </chapter> |
219 | |
220 | <chapter> |
221 | |
222 | === modified file 'doc/reference/zeitgeist-1.0-sections.txt' |
223 | --- doc/reference/zeitgeist-1.0-sections.txt 2010-06-10 07:45:03 +0000 |
224 | +++ doc/reference/zeitgeist-1.0-sections.txt 2010-06-17 14:14:24 +0000 |
225 | @@ -3,8 +3,6 @@ |
226 | <TITLE>ZeitgeistTimeRange</TITLE> |
227 | ZeitgeistTimeRange |
228 | ZeitgeistTimeRangeClass |
229 | -ZEITGEIST_GTIMEVAL_TO_TIMESTAMP |
230 | -ZEITGEIST_TIMESTAMP_TO_GTIMEVAL |
231 | zeitgeist_time_range_new |
232 | zeitgeist_time_range_new_from_now |
233 | zeitgeist_time_range_new_to_now |
234 | @@ -283,7 +281,7 @@ |
235 | <FILE>zeitgeist-result-set</FILE> |
236 | <TITLE>ZeitgeistResultSet</TITLE> |
237 | ZeitgeistResultSet |
238 | -ZeitgeistResultSetClass |
239 | +ZeitgeistResultSetIface |
240 | zeitgeist_result_set_size |
241 | zeitgeist_result_set_estimated_matches |
242 | zeitgeist_result_set_next |
243 | @@ -297,4 +295,23 @@ |
244 | ZEITGEIST_TYPE_RESULT_SET |
245 | ZEITGEIST_RESULT_SET_GET_IFACE |
246 | zeitgeist_result_set_get_type |
247 | -</SECTION> |
248 | \ No newline at end of file |
249 | +</SECTION> |
250 | + |
251 | +<SECTION> |
252 | +<FILE>zeitgeist-timestamp</FILE> |
253 | +<TITLE>Timestamp handling</TITLE> |
254 | +ZEITGEIST_TIMESTAMP_SECOND |
255 | +ZEITGEIST_TIMESTAMP_MINUTE |
256 | +ZEITGEIST_TIMESTAMP_HOUR |
257 | +ZEITGEIST_TIMESTAMP_DAY |
258 | +ZEITGEIST_TIMESTAMP_WEEK |
259 | +ZEITGEIST_TIMESTAMP_YEAR |
260 | +zeitgeist_timestamp_for_now |
261 | +zeitgeist_timestamp_from_timeval |
262 | +zeitgeist_timestamp_to_timeval |
263 | +zeitgeist_timestamp_from_iso8601 |
264 | +zeitgeist_timestamp_to_iso8601 |
265 | +zeitgeist_timestamp_from_date |
266 | +zeitgeist_timestamp_from_dmy |
267 | +zeitgeist_timestamp_to_date |
268 | +</SECTION> |
269 | |
270 | === modified file 'src/Makefile.am' |
271 | --- src/Makefile.am 2010-06-09 21:15:49 +0000 |
272 | +++ src/Makefile.am 2010-06-17 14:14:24 +0000 |
273 | @@ -125,6 +125,8 @@ |
274 | zeitgeist-subject.h \ |
275 | zeitgeist-timerange.c \ |
276 | zeitgeist-timerange.h \ |
277 | + zeitgeist-timestamp.c \ |
278 | + zeitgeist-timestamp.h \ |
279 | zeitgeist.h \ |
280 | $(eggzeitgeist_sources) \ |
281 | $(NULL) |
282 | @@ -151,6 +153,7 @@ |
283 | zeitgeist-result-set.h \ |
284 | zeitgeist-subject.h \ |
285 | zeitgeist-timerange.h \ |
286 | + zeitgeist-timestamp.h \ |
287 | zeitgeist.h |
288 | |
289 | devel_headers_HEADERS = \ |
290 | |
291 | === modified file 'src/zeitgeist-event.c' |
292 | --- src/zeitgeist-event.c 2010-06-10 09:43:09 +0000 |
293 | +++ src/zeitgeist-event.c 2010-06-17 14:14:24 +0000 |
294 | @@ -134,7 +134,7 @@ |
295 | * Get the event timestamp. The timestamp is in milliseconds since the |
296 | * Unix epoch. There are a few helpers available for converting to and |
297 | * from other time representations such a #GTimeVal. See for example |
298 | - * ZEITGEIST_TIMESTAMP_TO_GTIMEVAL() and ZEITGEIST_GTIMEVAL_TO_TIMESTAMP(). |
299 | + * zeitgeist_timestamp_to_timeval() and zeitgeist_timestamp_from_timeval(). |
300 | * |
301 | * Returns: The event timestamp. Note that 0 is ambiguous as it denotes both |
302 | * an unset timestamp and the time of the Unix Epoch. |
303 | @@ -155,7 +155,7 @@ |
304 | * Set the event timestamp. The timestamp is in milliseconds since the |
305 | * Unix epoch. There are a few helpers available for converting to and |
306 | * from other time representations such a #GTimeVal. See for example |
307 | - * ZEITGEIST_TIMESTAMP_TO_GTIMEVAL() and ZEITGEIST_GTIMEVAL_TO_TIMESTAMP(). |
308 | + * zeitgeist_timestamp_to_timeval() and zeitgeist_timestamp_from_timeval(). |
309 | * |
310 | * Note that the if you insert events into the Zeitgeist log without a |
311 | * timestamp set the Zeiteist daemon will automatically assign the timestamp |
312 | |
313 | === modified file 'src/zeitgeist-timerange.c' |
314 | --- src/zeitgeist-timerange.c 2010-04-22 12:31:21 +0000 |
315 | +++ src/zeitgeist-timerange.c 2010-06-17 14:14:24 +0000 |
316 | @@ -112,7 +112,7 @@ |
317 | GTimeVal tv; |
318 | |
319 | g_get_current_time (&tv); |
320 | - time_range = zeitgeist_time_range_new (ZEITGEIST_GTIMEVAL_TO_TIMESTAMP (&tv), |
321 | + time_range = zeitgeist_time_range_new (zeitgeist_timestamp_from_timeval (&tv), |
322 | G_MAXINT64); |
323 | |
324 | return time_range; |
325 | @@ -132,7 +132,7 @@ |
326 | |
327 | g_get_current_time (&tv); |
328 | time_range = |
329 | - zeitgeist_time_range_new (0, ZEITGEIST_GTIMEVAL_TO_TIMESTAMP (&tv)); |
330 | + zeitgeist_time_range_new (0, zeitgeist_timestamp_from_timeval (&tv)); |
331 | |
332 | return time_range; |
333 | } |
334 | @@ -204,8 +204,8 @@ |
335 | |
336 | g_return_val_if_fail (ZEITGEIST_IS_TIME_RANGE (time_range), NULL); |
337 | |
338 | - ZEITGEIST_TIMESTAMP_TO_GTIMEVAL (zeitgeist_time_range_get_start (time_range), |
339 | - &tv); |
340 | + zeitgeist_timestamp_to_timeval (zeitgeist_time_range_get_start (time_range), |
341 | + &tv); |
342 | return g_time_val_to_iso8601 (&tv); |
343 | } |
344 | |
345 | @@ -227,7 +227,7 @@ |
346 | |
347 | g_return_val_if_fail (ZEITGEIST_IS_TIME_RANGE (time_range), NULL); |
348 | |
349 | - ZEITGEIST_TIMESTAMP_TO_GTIMEVAL (zeitgeist_time_range_get_end (time_range), |
350 | - &tv); |
351 | + zeitgeist_timestamp_to_timeval (zeitgeist_time_range_get_end (time_range), |
352 | + &tv); |
353 | return g_time_val_to_iso8601 (&tv); |
354 | } |
355 | |
356 | === modified file 'src/zeitgeist-timerange.h' |
357 | --- src/zeitgeist-timerange.h 2010-06-16 13:17:00 +0000 |
358 | +++ src/zeitgeist-timerange.h 2010-06-17 14:14:24 +0000 |
359 | @@ -49,30 +49,6 @@ |
360 | GInitiallyUnowned parent_instance; |
361 | }; |
362 | |
363 | -/** |
364 | - * ZEITGEIST_GTIMEVAL_TO_TIMESTAMP: |
365 | - * @gtimeval: A #GTimeVal instance |
366 | - * |
367 | - * Returns: A #gint64 with the total number of milliseconds since the Unix Epoch |
368 | - */ |
369 | -#define ZEITGEIST_GTIMEVAL_TO_TIMESTAMP(gtimeval) \ |
370 | - (((gint64)(gtimeval)->tv_sec)*1000 + ((gint64)(gtimeval)->tv_usec)/1000) |
371 | - |
372 | -/** |
373 | - * ZEITGEIST_TIMESTAMP_TO_GTIMEVAL: |
374 | - * @timestamp: A #gint64 with a number of milliseconds since the Unix Epoch |
375 | - * @gtimeval: A #GTimeVal instance to store the result in |
376 | - * |
377 | - * Write a Zeitgeist timestamp to a #GTimeVal instance. Note that Zeitgeist |
378 | - * uses only a millisecond resolution for where #GTimeVal uses a microsecond |
379 | - * resolution, meaning that the lower three digits of @gtimeval.tv_usec will |
380 | - * be 0. |
381 | - * |
382 | - * Returns: Nothing. The result is stored in @gtimeval |
383 | - */ |
384 | -#define ZEITGEIST_TIMESTAMP_TO_GTIMEVAL(systime, gtimeval) \ |
385 | - ((gtimeval)->tv_sec = systime/1000, (gtimeval)->tv_usec = (systime%1000)*1000) |
386 | - |
387 | GType zeitgeist_time_range_get_type (void); |
388 | |
389 | ZeitgeistTimeRange* |
390 | |
391 | === added file 'src/zeitgeist-timestamp.c' |
392 | --- src/zeitgeist-timestamp.c 1970-01-01 00:00:00 +0000 |
393 | +++ src/zeitgeist-timestamp.c 2010-06-17 14:14:24 +0000 |
394 | @@ -0,0 +1,194 @@ |
395 | +/* |
396 | + * Copyright (C) 2010 Canonical, Ltd. |
397 | + * |
398 | + * This library is free software; you can redistribute it and/or modify |
399 | + * it under the terms of the GNU Lesser General Public License |
400 | + * version 3.0 as published by the Free Software Foundation. |
401 | + * |
402 | + * This library is distributed in the hope that it will be useful, |
403 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
404 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
405 | + * GNU Lesser General Public License version 3.0 for more details. |
406 | + * |
407 | + * You should have received a copy of the GNU Lesser General Public |
408 | + * License along with this library. If not, see |
409 | + * <http://www.gnu.org/licenses/>. |
410 | + * |
411 | + * Authored by |
412 | + * Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com> |
413 | + */ |
414 | + |
415 | +#include "zeitgeist-timerange.h" |
416 | + |
417 | +/** |
418 | + * SECTION:zeitgeist-timestamp |
419 | + * @short_description: Convenience functions for dealing with timestamps and dates |
420 | + * @include: zeitgeist.h |
421 | + * |
422 | + * A suite of convenience functions for dealing with timestamps and dates. |
423 | + * |
424 | + * Zeitgeist timestamps are represented as #gint64<!-- -->s with the number |
425 | + * of milliseconds since the Unix Epoch. |
426 | + */ |
427 | +#if HAVE_CONFIG_H |
428 | +#include <config.h> |
429 | +#endif |
430 | + |
431 | +#include "zeitgeist-timestamp.h" |
432 | + |
433 | +/** |
434 | + * zeitgeist_timestamp_from_timeval: |
435 | + * @tv: A #GTimeVal instance |
436 | + * |
437 | + * Returns: A #gint64 with the total number of milliseconds since the Unix Epoch |
438 | + */ |
439 | +gint64 |
440 | +zeitgeist_timestamp_from_timeval (GTimeVal *tv) |
441 | +{ |
442 | + g_return_if_fail (tv != NULL); |
443 | + |
444 | + return (((gint64)tv->tv_sec)*1000 + ((gint64)tv->tv_usec)/1000); |
445 | +} |
446 | + |
447 | +/** |
448 | + * zeitgeist_timestamp_to_timeval: |
449 | + * @timestamp: A #gint64 with a number of milliseconds since the Unix Epoch |
450 | + * @tv: A #GTimeVal instance to store the result in |
451 | + * |
452 | + * Write a Zeitgeist timestamp to a #GTimeVal instance. Note that Zeitgeist |
453 | + * uses only a millisecond resolution for where #GTimeVal uses a microsecond |
454 | + * resolution, meaning that the lower three digits of @tv.tv_usec will |
455 | + * be 0. |
456 | + * |
457 | + * Returns: Nothing. The result is stored in @tv |
458 | + */ |
459 | +void |
460 | +zeitgeist_timestamp_to_timeval (gint64 timestamp, GTimeVal *tv) |
461 | +{ |
462 | + g_return_if_fail (tv != NULL); |
463 | + |
464 | + tv->tv_sec = timestamp / 1000; |
465 | + tv->tv_usec = (timestamp % 1000) * 1000; |
466 | +} |
467 | + |
468 | +/** |
469 | + * zeitgeist_timestamp_for_now: |
470 | + * |
471 | + * Get the timestamp for the current system time |
472 | + * |
473 | + * Returns: The timestamp for the current system time. Ie. the number of |
474 | + * milliseconds since the Unix Epoch |
475 | + */ |
476 | +gint64 |
477 | +zeitgeist_timestamp_for_now (void) |
478 | +{ |
479 | + GTimeVal tv; |
480 | + |
481 | + g_get_current_time (&tv); |
482 | + return zeitgeist_timestamp_from_timeval (&tv); |
483 | +} |
484 | + |
485 | +/** |
486 | + * zeitgeist_timestamp_from_iso8601: |
487 | + * @datetime: A string containing an iso8601 conforming datetime specification |
488 | + * |
489 | + * Parse a timestamp from a ISO8601 encoded string. |
490 | + * |
491 | + * Returns: The timestamp represented by @datetime, or -1 on failure to parse |
492 | + * @datetime |
493 | + */ |
494 | +gint64 |
495 | +zeitgeist_timestamp_from_iso8601 (const gchar *datetime) |
496 | +{ |
497 | + GTimeVal tv; |
498 | + |
499 | + g_return_if_fail (datetime != NULL); |
500 | + |
501 | + if (g_time_val_from_iso8601 (datetime, &tv)) |
502 | + return zeitgeist_timestamp_from_timeval (&tv); |
503 | + else |
504 | + return -1; |
505 | +} |
506 | + |
507 | +/** |
508 | + * zeitgeist_timestamp_to_iso8601: |
509 | + * @timestamp: A Zeitgeist timestamp in ms since the Epoch |
510 | + * |
511 | + * Convert a timestamp to a human readable ISO8601 format |
512 | + * |
513 | + * Returns: A newly allocated string containing the ISO8601 format of |
514 | + * @timestamp. Free with g_free(). |
515 | + */ |
516 | +gchar* |
517 | +zeitgeist_timestamp_to_iso8601 (gint64 timestamp) |
518 | +{ |
519 | + GTimeVal tv; |
520 | + |
521 | + zeitgeist_timestamp_to_timeval (timestamp, &tv); |
522 | + return g_time_val_to_iso8601 (&tv); |
523 | +} |
524 | + |
525 | +/** |
526 | + * zeitgeist_timestamp_from_date: |
527 | + * @date: A #GDate to convert |
528 | + * |
529 | + * Convert a #GDate to a Zeitgeist timestamp. |
530 | + * |
531 | + * Returns: @date as a timestamp in milliseconds since the Epoch |
532 | + */ |
533 | +gint64 |
534 | +zeitgeist_timestamp_from_date (GDate *date) |
535 | +{ |
536 | + g_return_val_if_fail (date != NULL, -1); |
537 | + |
538 | + gint64 julian = g_date_get_julian (date); |
539 | + |
540 | + gint64 foo = ZEITGEIST_TIMESTAMP_YEAR; |
541 | + |
542 | + return julian*ZEITGEIST_TIMESTAMP_DAY - 1969*ZEITGEIST_TIMESTAMP_YEAR; |
543 | +} |
544 | + |
545 | +/** |
546 | + * zeitgeist_timestamp_from_dmy: |
547 | + * @day: The day of the month represented as a #GDateDay |
548 | + * @month: The month of the year represented as a #GDateMonth |
549 | + * @year: The year represented as a #GDateYear |
550 | + * |
551 | + * Convert a day, month, year tuple into a Zeitgeist timestamp |
552 | + * |
553 | + * Returns: Input data as a timestamp in milliseconds since the Epoch or |
554 | + * -1 in case the provided data does not constitute a valid date |
555 | + */ |
556 | +gint64 |
557 | +zeitgeist_timestamp_from_dmy (GDateDay day, |
558 | + GDateMonth month, |
559 | + GDateYear year) |
560 | +{ |
561 | + GDate date = { 0 }; |
562 | + |
563 | + g_return_val_if_fail (g_date_valid_dmy (day, month, year), -1); |
564 | + |
565 | + g_date_set_dmy (&date, day, month, year); |
566 | + return zeitgeist_timestamp_from_date (&date); |
567 | +} |
568 | + |
569 | +/** |
570 | + * zeitgeist_timestamp_to_date: |
571 | + * @timestamp: The Zeitgeist timestamp to convert to a #GDate |
572 | + * @date: The place to store the result in. Must be non-%NULL |
573 | + * |
574 | + * Write a timestamp to a #GDate structure |
575 | + * |
576 | + * Returns: Nothing. The return value is written to @date |
577 | + */ |
578 | +void |
579 | +zeitgeist_timestamp_to_date (gint64 timestamp, |
580 | + GDate *date) |
581 | +{ |
582 | + GTimeVal tv; |
583 | + |
584 | + g_return_if_fail (date != NULL); |
585 | + |
586 | + zeitgeist_timestamp_to_timeval (timestamp, &tv); |
587 | + g_date_set_time_val (date, &tv); |
588 | +} |
589 | |
590 | === added file 'src/zeitgeist-timestamp.h' |
591 | --- src/zeitgeist-timestamp.h 1970-01-01 00:00:00 +0000 |
592 | +++ src/zeitgeist-timestamp.h 2010-06-17 14:14:24 +0000 |
593 | @@ -0,0 +1,100 @@ |
594 | +/* |
595 | + * Copyright (C) 2010 Canonical, Ltd. |
596 | + * |
597 | + * This library is free software; you can redistribute it and/or modify |
598 | + * it under the terms of the GNU Lesser General Public License |
599 | + * version 3.0 as published by the Free Software Foundation. |
600 | + * |
601 | + * This library is distributed in the hope that it will be useful, |
602 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
603 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
604 | + * GNU Lesser General Public License version 3.0 for more details. |
605 | + * |
606 | + * You should have received a copy of the GNU Lesser General Public |
607 | + * License along with this library. If not, see |
608 | + * <http://www.gnu.org/licenses/>. |
609 | + * |
610 | + * Authored by |
611 | + * Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com> |
612 | + */ |
613 | + |
614 | +#if !defined (_ZEITGEIST_H_INSIDE_) && !defined (ZEITGEIST_COMPILATION) |
615 | +#error "Only <zeitgeist.h> can be included directly." |
616 | +#endif |
617 | + |
618 | +#ifndef _ZEITGEIST_TIMESTAMP_H_ |
619 | +#define _ZEITGEIST_TIMESTaMP_H_ |
620 | + |
621 | +#include <glib.h> |
622 | + |
623 | +G_BEGIN_DECLS |
624 | + |
625 | +/** |
626 | + * ZEITGEIST_TIMESTAMP_SECOND: |
627 | + * |
628 | + * A second represented as a Zeitgeist timestamp (ie. 1000ms) |
629 | + */ |
630 | +#define ZEITGEIST_TIMESTAMP_SECOND 1000LL |
631 | + |
632 | +/** |
633 | + * ZEITGEIST_TIMESTAMP_MINUTE: |
634 | + * |
635 | + * A minute represented as a Zeitgeist timestamp (ie. 60000ms) |
636 | + */ |
637 | +#define ZEITGEIST_TIMESTAMP_MINUTE 60000LL |
638 | + |
639 | +/** |
640 | + * ZEITGEIST_TIMESTAMP_HOUR: |
641 | + * |
642 | + * An hour represented as a Zeitgeist timestamp (ie. 3600000ms) |
643 | + */ |
644 | +#define ZEITGEIST_TIMESTAMP_HOUR 3600000LL |
645 | + |
646 | +/** |
647 | + * ZEITGEIST_TIMESTAMP_DAY: |
648 | + * |
649 | + * A day represented as a Zeitgeist timestamp (ie. 86400000ms) |
650 | + */ |
651 | +#define ZEITGEIST_TIMESTAMP_DAY 86400000LL |
652 | + |
653 | +/** |
654 | + * ZEITGEIST_TIMESTAMP_WEEK: |
655 | + * |
656 | + * A week represented as a Zeitgeist timestamp (ie. 604800000ms) |
657 | + */ |
658 | +#define ZEITGEIST_TIMESTAMP_WEEK 604800000LL |
659 | + |
660 | +/** |
661 | + * ZEITGEIST_TIMESTAMP_YEAR: |
662 | + * |
663 | + * A year represented as a Zeitgeist timestamp (ie. 31556952000ms). |
664 | + * Be warned that a year is not 365 days, but in fact 365.2425 days to |
665 | + * account for leap years. |
666 | + */ |
667 | +#define ZEITGEIST_TIMESTAMP_YEAR 31556952000LL |
668 | + |
669 | +gint64 zeitgeist_timestamp_for_now (void); |
670 | + |
671 | +gint64 zeitgeist_timestamp_from_timeval (GTimeVal *tv); |
672 | + |
673 | +void zeitgeist_timestamp_to_timeval (gint64 timestamp, |
674 | + GTimeVal *tv); |
675 | + |
676 | +gint64 zeitgeist_timestamp_from_iso8601 (const gchar *datetime); |
677 | + |
678 | +gchar* zeitgeist_timestamp_to_iso8601 (gint64 timestamp); |
679 | + |
680 | +gint64 zeitgeist_timestamp_from_date (GDate *date); |
681 | + |
682 | +gint64 zeitgeist_timestamp_from_dmy (GDateDay day, |
683 | + GDateMonth month, |
684 | + GDateYear year); |
685 | + |
686 | +void zeitgeist_timestamp_to_date (gint64 timestamp, |
687 | + GDate *date); |
688 | + |
689 | + |
690 | + |
691 | +G_END_DECLS |
692 | + |
693 | +#endif /* _ZEITGEIST_TIMESTAMP_H_ */ |
694 | |
695 | === modified file 'src/zeitgeist.h' |
696 | --- src/zeitgeist.h 2010-06-09 20:38:14 +0000 |
697 | +++ src/zeitgeist.h 2010-06-17 14:14:24 +0000 |
698 | @@ -35,6 +35,7 @@ |
699 | #include <zeitgeist-result-set.h> |
700 | #include <zeitgeist-subject.h> |
701 | #include <zeitgeist-timerange.h> |
702 | +#include <zeitgeist-timestamp.h> |
703 | |
704 | #undef _ZEITGEIST_H_INSIDE_ |
705 | |
706 | |
707 | === modified file 'tests/Makefile.am' |
708 | --- tests/Makefile.am 2010-06-10 10:19:33 +0000 |
709 | +++ tests/Makefile.am 2010-06-17 14:14:24 +0000 |
710 | @@ -34,6 +34,10 @@ |
711 | test_timerange_SOURCES = test-timerange.c $(helper_sources) |
712 | test_timerange_LDADD = $(zeitgeist_libs) |
713 | |
714 | +TEST_PROGS += test-timestamp |
715 | +test_timestamp_SOURCES = test-timestamp.c $(helper_sources) |
716 | +test_timestamp_LDADD = $(zeitgeist_libs) |
717 | + |
718 | TEST_PROGS += test-monitor |
719 | test_monitor_SOURCES = test-monitor.c $(helper_sources) |
720 | test_monitor_LDADD = $(zeitgeist_libs) |
721 | |
722 | === added file 'tests/test-timestamp.c' |
723 | --- tests/test-timestamp.c 1970-01-01 00:00:00 +0000 |
724 | +++ tests/test-timestamp.c 2010-06-17 14:14:24 +0000 |
725 | @@ -0,0 +1,96 @@ |
726 | +/* |
727 | + * Copyright (C) 2010 Canonical Ltd |
728 | + * |
729 | + * This program is free software: you can redistribute it and/or modify |
730 | + * it under the terms of the GNU General Public License version 3 as |
731 | + * published by the Free Software Foundation. |
732 | + * |
733 | + * This program is distributed in the hope that it will be useful, |
734 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
735 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
736 | + * GNU General Public License for more details. |
737 | + * |
738 | + * You should have received a copy of the GNU General Public License |
739 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
740 | + * |
741 | + * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com> |
742 | + * |
743 | + */ |
744 | + |
745 | +#include <glib.h> |
746 | +#include <glib-object.h> |
747 | +#include "zeitgeist-timestamp.h" |
748 | + |
749 | +typedef struct |
750 | +{ |
751 | + |
752 | +} Fixture; |
753 | + |
754 | +static void setup (Fixture *fix, gconstpointer data); |
755 | +static void teardown (Fixture *fix, gconstpointer data); |
756 | + |
757 | +static void |
758 | +setup (Fixture *fix, gconstpointer data) |
759 | +{ |
760 | + |
761 | +} |
762 | + |
763 | +static void |
764 | +teardown (Fixture *fix, gconstpointer data) |
765 | +{ |
766 | + |
767 | +} |
768 | + |
769 | +static void |
770 | +test_from_iso8601 (Fixture *fix, gconstpointer data) |
771 | +{ |
772 | + const gchar *orig = "2010-06-17T00:00:00Z"; |
773 | + gint64 from_iso = zeitgeist_timestamp_from_iso8601 (orig); |
774 | + gchar *d = zeitgeist_timestamp_to_iso8601 (from_iso); |
775 | + |
776 | + g_assert_cmpstr (orig, ==, d); |
777 | + g_free (d); |
778 | +} |
779 | + |
780 | +static void |
781 | +test_inc_year (Fixture *fix, gconstpointer data) |
782 | +{ |
783 | + gchar *d = zeitgeist_timestamp_to_iso8601 (ZEITGEIST_TIMESTAMP_YEAR); |
784 | + |
785 | + // Since ZEITGEIST_TIMESTAMP_YEAR accounts for leap years we wont exactly |
786 | + // match "1971-01-01T00:00:00Z" on the hour |
787 | + g_assert (g_str_has_prefix (d, "1971-01-01T")); |
788 | + g_free (d); |
789 | +} |
790 | + |
791 | +static void |
792 | +test_from_date (Fixture *fix, gconstpointer data) |
793 | +{ |
794 | + GDate date = { 0 }; |
795 | + |
796 | + g_date_set_dmy (&date, 25, G_DATE_JUNE, 2000); |
797 | + gint64 from_date = zeitgeist_timestamp_from_date (&date); |
798 | + |
799 | + gchar *d = zeitgeist_timestamp_to_iso8601 (from_date); |
800 | + |
801 | + // Since ZEITGEIST_TIMESTAMP_YEAR accounts for leap years we wont exactly |
802 | + // match "2000-06-25T00:00:00Z" on the hour |
803 | + g_assert (g_str_has_prefix (d, "2000-06-25T")); |
804 | +} |
805 | + |
806 | +int |
807 | +main (int argc, |
808 | + char *argv[]) |
809 | +{ |
810 | + g_type_init (); |
811 | + g_test_init (&argc, &argv, NULL); |
812 | + |
813 | + g_test_add ("/Zeitgeist/TimeRange/FromISO8601", Fixture, NULL, |
814 | + setup, test_from_iso8601, teardown); |
815 | + g_test_add ("/Zeitgeist/TimeRange/IncrementYear", Fixture, NULL, |
816 | + setup, test_inc_year, teardown); |
817 | + g_test_add ("/Zeitgeist/TimeRange/FromDate", Fixture, NULL, |
818 | + setup, test_from_date, teardown); |
819 | + |
820 | + return g_test_run(); |
821 | +} |
822 | \ No newline at end of file |