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