Merge lp:~libzeitgeist-developers/libzeitgeist/timestamps into lp:libzeitgeist

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
Reviewer Review Type Date Requested Status
LibZeitgeist Developers Pending
Review via email: mp+27822@code.launchpad.net

Description of the change

Add a new namespace Zeitgeist.TimeStamp/zeitgeist_timestamp with convenience functions and constants for dealing with timestamps.

The following macros have been changed:

   - ZEITGEIST_TIMESTAMP_TO_GTIMEVAL is now zeitgeist_timestamp_to_timeval
   - ZEITGEIST_GTIMEVAL_TO_TIMESTAMP is now zeitgeist_timestamp_from_timeval

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
=== modified file 'bindings/zeitgeist-1.0-custom.vala'
--- bindings/zeitgeist-1.0-custom.vala 2010-06-17 08:27:02 +0000
+++ bindings/zeitgeist-1.0-custom.vala 2010-06-17 14:14:24 +0000
@@ -30,11 +30,51 @@
30 [CCode (cname = "_vala_zeitgeist_result_set_iterator")]30 [CCode (cname = "_vala_zeitgeist_result_set_iterator")]
31 public ResultSet iterator ();31 public ResultSet iterator ();
32 }32 }
33 33}
34 [CCode (cname = "ZEITGEIST_GTIMEVAL_TO_TIMESTAMP")]34
35 public static int64 timeval_to_timestamp (GLib.TimeVal time_val);35namespace Zeitgeist.Timestamp
36 [CCode (cname = "ZEITGEIST_TIMESTAMP_TO_GTIMEVAL")]36{
37 public static GLib.TimeVal timestamp_to_timeval (int64 timestamp);37 [CCode (cname = "ZEITGEIST_TIMESTAMP_SECOND", cheader_filename = "zeitgeist.h")]
38 public int64 SECOND;
39
40 [CCode (cname = "ZEITGEIST_TIMESTAMP_MINUTE", cheader_filename = "zeitgeist.h")]
41 public int64 MINUTE;
42
43 [CCode (cname = "ZEITGEIST_TIMESTAMP_HOUR", cheader_filename = "zeitgeist.h")]
44 public int64 HOUR;
45
46 [CCode (cname = "ZEITGEIST_TIMESTAMP_DAY", cheader_filename = "zeitgeist.h")]
47 public int64 DAY;
48
49 [CCode (cname = "ZEITGEIST_TIMESTAMP_WEEK", cheader_filename = "zeitgeist.h")]
50 public int64 WEEK;
51
52 [CCode (cname = "ZEITGEIST_TIMESTAMP_YEAR", cheader_filename = "zeitgeist.h")]
53 public int64 YEAR;
54
55 [CCode (cname = "zeitgeist_timestamp_for_now", cheader_filename = "zeitgeist.h")]
56 public int64 now ();
57
58 [CCode (cname = "zeitgeist_timestamp_from_timeval", cheader_filename = "zeitgeist.h")]
59 public int64 from_timeval (GLib.TimeVal tv);
60
61 [CCode (cname = "zeitgeist_timestamp_to_timeval", cheader_filename = "zeitgeist.h")]
62 public int64 to_timeval (int64 timestamp, out GLib.TimeVal tv);
63
64 [CCode (cname = "zeitgeist_timestamp_from_iso8601", cheader_filename = "zeitgeist.h")]
65 public int64 from_iso8601 (string datetime);
66
67 [CCode (cname = "zeitgeist_timestamp_to_iso8601", cheader_filename = "zeitgeist.h")]
68 public string to_iso8601 (int64 timestamp);
69
70 [CCode (cname = "zeitgeist_timestamp_from_date", cheader_filename = "zeitgeist.h")]
71 public int64 from_date (GLib.Date date);
72
73 [CCode (cname = "zeitgeist_timestamp_from_dmy", cheader_filename = "zeitgeist.h")]
74 public int64 from_dmy (GLib.DateDay day, GLib.DateMonth month, GLib.DateYear year);
75
76 [CCode (cname = "zeitgeist_timestamp_to_date", cheader_filename = "zeitgeist.h")]
77 public int64 to_date (int64 timestamp, out GLib.Date date);
38}78}
3979
40// vim:et:ai:cindent:ts=2 sts=2 sw=2:80// vim:et:ai:cindent:ts=2 sts=2 sw=2:
4181
=== modified file 'bindings/zeitgeist-1.0.gi'
--- bindings/zeitgeist-1.0.gi 2010-06-10 09:43:09 +0000
+++ bindings/zeitgeist-1.0.gi 2010-06-17 14:14:24 +0000
@@ -34,6 +34,55 @@
34 <parameter name="manifestation_type" type="gchar*"/>34 <parameter name="manifestation_type" type="gchar*"/>
35 </parameters>35 </parameters>
36 </function>36 </function>
37 <function name="timestamp_for_now" symbol="zeitgeist_timestamp_for_now">
38 <return-type type="gint64"/>
39 </function>
40 <function name="timestamp_from_date" symbol="zeitgeist_timestamp_from_date">
41 <return-type type="gint64"/>
42 <parameters>
43 <parameter name="date" type="GDate*"/>
44 </parameters>
45 </function>
46 <function name="timestamp_from_dmy" symbol="zeitgeist_timestamp_from_dmy">
47 <return-type type="gint64"/>
48 <parameters>
49 <parameter name="day" type="GDateDay"/>
50 <parameter name="month" type="GDateMonth"/>
51 <parameter name="year" type="GDateYear"/>
52 </parameters>
53 </function>
54 <function name="timestamp_from_iso8601" symbol="zeitgeist_timestamp_from_iso8601">
55 <return-type type="gint64"/>
56 <parameters>
57 <parameter name="datetime" type="gchar*"/>
58 </parameters>
59 </function>
60 <function name="timestamp_from_timeval" symbol="zeitgeist_timestamp_from_timeval">
61 <return-type type="gint64"/>
62 <parameters>
63 <parameter name="tv" type="GTimeVal*"/>
64 </parameters>
65 </function>
66 <function name="timestamp_to_date" symbol="zeitgeist_timestamp_to_date">
67 <return-type type="void"/>
68 <parameters>
69 <parameter name="timestamp" type="gint64"/>
70 <parameter name="date" type="GDate*"/>
71 </parameters>
72 </function>
73 <function name="timestamp_to_iso8601" symbol="zeitgeist_timestamp_to_iso8601">
74 <return-type type="gchar*"/>
75 <parameters>
76 <parameter name="timestamp" type="gint64"/>
77 </parameters>
78 </function>
79 <function name="timestamp_to_timeval" symbol="zeitgeist_timestamp_to_timeval">
80 <return-type type="void"/>
81 <parameters>
82 <parameter name="timestamp" type="gint64"/>
83 <parameter name="tv" type="GTimeVal*"/>
84 </parameters>
85 </function>
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">
38 <member name="ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS" value="0"/>87 <member name="ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS" value="0"/>
39 <member name="ZEITGEIST_RESULT_TYPE_LEAST_RECENT_EVENTS" value="1"/>88 <member name="ZEITGEIST_RESULT_TYPE_LEAST_RECENT_EVENTS" value="1"/>
@@ -781,6 +830,12 @@
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"/>
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"/>
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"/>
833 <constant name="ZEITGEIST_TIMESTAMP_DAY" type="int" value="86400000"/>
834 <constant name="ZEITGEIST_TIMESTAMP_HOUR" type="int" value="3600000"/>
835 <constant name="ZEITGEIST_TIMESTAMP_MINUTE" type="int" value="60000"/>
836 <constant name="ZEITGEIST_TIMESTAMP_SECOND" type="int" value="1000"/>
837 <constant name="ZEITGEIST_TIMESTAMP_WEEK" type="int" value="604800000"/>
838 <constant name="ZEITGEIST_TIMESTAMP_YEAR" type="int" value="2147483647"/>
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"/>
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"/>
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"/>
787842
=== modified file 'bindings/zeitgeist-1.0.metadata'
--- bindings/zeitgeist-1.0.metadata 2010-06-16 13:18:59 +0000
+++ bindings/zeitgeist-1.0.metadata 2010-06-17 14:14:24 +0000
@@ -1,4 +1,5 @@
1Zeitgeist cheader_filename="zeitgeist.h"1Zeitgeist cheader_filename="zeitgeist.h"
2Zeitgeist.Timestamp cheader_filename="zeitgeist.h"
2zeitgeist_index_search async="1"3zeitgeist_index_search async="1"
3zeitgeist_index_search.event_templates transfer_ownership="1"4zeitgeist_index_search.event_templates transfer_ownership="1"
4zeitgeist_index_search_finish transfer_ownership="1"5zeitgeist_index_search_finish transfer_ownership="1"
@@ -34,3 +35,6 @@
3435
35zeitgeist_log_*.cancellable nullable="1"36zeitgeist_log_*.cancellable nullable="1"
36zeitgeist_index_*.cancellable nullable="1"37zeitgeist_index_*.cancellable nullable="1"
38
39zeitgeist_timestamp_* hidden="1"
40ZEITGEIST_TIMESTAMP_* hidden="1"
3741
=== modified file 'bindings/zeitgeist-1.0.namespace'
--- bindings/zeitgeist-1.0.namespace 2010-04-19 11:11:55 +0000
+++ bindings/zeitgeist-1.0.namespace 2010-06-17 14:14:24 +0000
@@ -1,1 +1,2 @@
1Zeitgeist1Zeitgeist
2Zeitgeist.Timestamp
23
=== modified file 'bindings/zeitgeist-1.0.vapi'
--- bindings/zeitgeist-1.0.vapi 2010-06-17 08:27:02 +0000
+++ bindings/zeitgeist-1.0.vapi 2010-06-17 14:14:24 +0000
@@ -2,6 +2,37 @@
22
3[CCode (cprefix = "Zeitgeist", lower_case_cprefix = "zeitgeist_")]3[CCode (cprefix = "Zeitgeist", lower_case_cprefix = "zeitgeist_")]
4namespace Zeitgeist {4namespace Zeitgeist {
5 [CCode (cprefix = "ZeitgeistTimestamp", lower_case_cprefix = "zeitgeist_timestamp_")]
6 namespace Timestamp {
7 [CCode (cname = "ZEITGEIST_TIMESTAMP_DAY", cheader_filename = "zeitgeist.h")]
8 public static int64 DAY;
9 [CCode (cname = "ZEITGEIST_TIMESTAMP_HOUR", cheader_filename = "zeitgeist.h")]
10 public static int64 HOUR;
11 [CCode (cname = "ZEITGEIST_TIMESTAMP_MINUTE", cheader_filename = "zeitgeist.h")]
12 public static int64 MINUTE;
13 [CCode (cname = "ZEITGEIST_TIMESTAMP_SECOND", cheader_filename = "zeitgeist.h")]
14 public static int64 SECOND;
15 [CCode (cname = "ZEITGEIST_TIMESTAMP_WEEK", cheader_filename = "zeitgeist.h")]
16 public static int64 WEEK;
17 [CCode (cname = "ZEITGEIST_TIMESTAMP_YEAR", cheader_filename = "zeitgeist.h")]
18 public static int64 YEAR;
19 [CCode (cheader_filename = "zeitgeist.h")]
20 public static int64 from_date (GLib.Date date);
21 [CCode (cheader_filename = "zeitgeist.h")]
22 public static int64 from_dmy (GLib.DateDay day, GLib.DateMonth month, GLib.DateYear year);
23 [CCode (cheader_filename = "zeitgeist.h")]
24 public static int64 from_iso8601 (string datetime);
25 [CCode (cheader_filename = "zeitgeist.h")]
26 public static int64 from_timeval (GLib.TimeVal tv);
27 [CCode (cname = "zeitgeist_timestamp_for_now", cheader_filename = "zeitgeist.h")]
28 public static int64 now ();
29 [CCode (cheader_filename = "zeitgeist.h")]
30 public static int64 to_date (int64 timestamp, out GLib.Date date);
31 [CCode (cheader_filename = "zeitgeist.h")]
32 public static string to_iso8601 (int64 timestamp);
33 [CCode (cheader_filename = "zeitgeist.h")]
34 public static int64 to_timeval (int64 timestamp, out GLib.TimeVal tv);
35 }
5 [CCode (cheader_filename = "zeitgeist.h")]36 [CCode (cheader_filename = "zeitgeist.h")]
6 public class Event : GLib.InitiallyUnowned {37 public class Event : GLib.InitiallyUnowned {
7 [CCode (has_construct_function = false)]38 [CCode (has_construct_function = false)]
@@ -316,8 +347,4 @@
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);
317 [CCode (cheader_filename = "zeitgeist.h")]348 [CCode (cheader_filename = "zeitgeist.h")]
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);
319 [CCode (cname = "ZEITGEIST_TIMESTAMP_TO_GTIMEVAL", cheader_filename = "zeitgeist.h")]
320 public static GLib.TimeVal timestamp_to_timeval (int64 timestamp);
321 [CCode (cname = "ZEITGEIST_GTIMEVAL_TO_TIMESTAMP", cheader_filename = "zeitgeist.h")]
322 public static int64 timeval_to_timestamp (GLib.TimeVal time_val);
323}350}
324351
=== modified file 'doc/reference/zeitgeist-1.0-docs.sgml'
--- doc/reference/zeitgeist-1.0-docs.sgml 2010-06-09 20:38:14 +0000
+++ doc/reference/zeitgeist-1.0-docs.sgml 2010-06-17 14:14:24 +0000
@@ -22,6 +22,7 @@
22 <chapter>22 <chapter>
23 <title>Utility Functions</title>23 <title>Utility Functions</title>
24 <xi:include href="xml/zeitgeist-mimetypes.xml"/>24 <xi:include href="xml/zeitgeist-mimetypes.xml"/>
25 <xi:include href="xml/zeitgeist-timestamp.xml"/>
25 </chapter>26 </chapter>
26 27
27 <chapter>28 <chapter>
2829
=== modified file 'doc/reference/zeitgeist-1.0-sections.txt'
--- doc/reference/zeitgeist-1.0-sections.txt 2010-06-10 07:45:03 +0000
+++ doc/reference/zeitgeist-1.0-sections.txt 2010-06-17 14:14:24 +0000
@@ -3,8 +3,6 @@
3<TITLE>ZeitgeistTimeRange</TITLE>3<TITLE>ZeitgeistTimeRange</TITLE>
4ZeitgeistTimeRange4ZeitgeistTimeRange
5ZeitgeistTimeRangeClass5ZeitgeistTimeRangeClass
6ZEITGEIST_GTIMEVAL_TO_TIMESTAMP
7ZEITGEIST_TIMESTAMP_TO_GTIMEVAL
8zeitgeist_time_range_new6zeitgeist_time_range_new
9zeitgeist_time_range_new_from_now7zeitgeist_time_range_new_from_now
10zeitgeist_time_range_new_to_now8zeitgeist_time_range_new_to_now
@@ -283,7 +281,7 @@
283<FILE>zeitgeist-result-set</FILE>281<FILE>zeitgeist-result-set</FILE>
284<TITLE>ZeitgeistResultSet</TITLE>282<TITLE>ZeitgeistResultSet</TITLE>
285ZeitgeistResultSet283ZeitgeistResultSet
286ZeitgeistResultSetClass284ZeitgeistResultSetIface
287zeitgeist_result_set_size285zeitgeist_result_set_size
288zeitgeist_result_set_estimated_matches286zeitgeist_result_set_estimated_matches
289zeitgeist_result_set_next287zeitgeist_result_set_next
@@ -297,4 +295,23 @@
297ZEITGEIST_TYPE_RESULT_SET295ZEITGEIST_TYPE_RESULT_SET
298ZEITGEIST_RESULT_SET_GET_IFACE296ZEITGEIST_RESULT_SET_GET_IFACE
299zeitgeist_result_set_get_type297zeitgeist_result_set_get_type
300</SECTION>
301\ No newline at end of file298\ No newline at end of file
299</SECTION>
300
301<SECTION>
302<FILE>zeitgeist-timestamp</FILE>
303<TITLE>Timestamp handling</TITLE>
304ZEITGEIST_TIMESTAMP_SECOND
305ZEITGEIST_TIMESTAMP_MINUTE
306ZEITGEIST_TIMESTAMP_HOUR
307ZEITGEIST_TIMESTAMP_DAY
308ZEITGEIST_TIMESTAMP_WEEK
309ZEITGEIST_TIMESTAMP_YEAR
310zeitgeist_timestamp_for_now
311zeitgeist_timestamp_from_timeval
312zeitgeist_timestamp_to_timeval
313zeitgeist_timestamp_from_iso8601
314zeitgeist_timestamp_to_iso8601
315zeitgeist_timestamp_from_date
316zeitgeist_timestamp_from_dmy
317zeitgeist_timestamp_to_date
318</SECTION>
302319
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2010-06-09 21:15:49 +0000
+++ src/Makefile.am 2010-06-17 14:14:24 +0000
@@ -125,6 +125,8 @@
125 zeitgeist-subject.h \125 zeitgeist-subject.h \
126 zeitgeist-timerange.c \126 zeitgeist-timerange.c \
127 zeitgeist-timerange.h \127 zeitgeist-timerange.h \
128 zeitgeist-timestamp.c \
129 zeitgeist-timestamp.h \
128 zeitgeist.h \130 zeitgeist.h \
129 $(eggzeitgeist_sources) \131 $(eggzeitgeist_sources) \
130 $(NULL)132 $(NULL)
@@ -151,6 +153,7 @@
151 zeitgeist-result-set.h \153 zeitgeist-result-set.h \
152 zeitgeist-subject.h \154 zeitgeist-subject.h \
153 zeitgeist-timerange.h \155 zeitgeist-timerange.h \
156 zeitgeist-timestamp.h \
154 zeitgeist.h157 zeitgeist.h
155158
156devel_headers_HEADERS = \159devel_headers_HEADERS = \
157160
=== modified file 'src/zeitgeist-event.c'
--- src/zeitgeist-event.c 2010-06-10 09:43:09 +0000
+++ src/zeitgeist-event.c 2010-06-17 14:14:24 +0000
@@ -134,7 +134,7 @@
134 * Get the event timestamp. The timestamp is in milliseconds since the134 * Get the event timestamp. The timestamp is in milliseconds since the
135 * Unix epoch. There are a few helpers available for converting to and135 * Unix epoch. There are a few helpers available for converting to and
136 * from other time representations such a #GTimeVal. See for example136 * from other time representations such a #GTimeVal. See for example
137 * ZEITGEIST_TIMESTAMP_TO_GTIMEVAL() and ZEITGEIST_GTIMEVAL_TO_TIMESTAMP().137 * zeitgeist_timestamp_to_timeval() and zeitgeist_timestamp_from_timeval().
138 *138 *
139 * Returns: The event timestamp. Note that 0 is ambiguous as it denotes both139 * Returns: The event timestamp. Note that 0 is ambiguous as it denotes both
140 * an unset timestamp and the time of the Unix Epoch.140 * an unset timestamp and the time of the Unix Epoch.
@@ -155,7 +155,7 @@
155 * Set the event timestamp. The timestamp is in milliseconds since the155 * Set the event timestamp. The timestamp is in milliseconds since the
156 * Unix epoch. There are a few helpers available for converting to and156 * Unix epoch. There are a few helpers available for converting to and
157 * from other time representations such a #GTimeVal. See for example157 * from other time representations such a #GTimeVal. See for example
158 * ZEITGEIST_TIMESTAMP_TO_GTIMEVAL() and ZEITGEIST_GTIMEVAL_TO_TIMESTAMP().158 * zeitgeist_timestamp_to_timeval() and zeitgeist_timestamp_from_timeval().
159 *159 *
160 * Note that the if you insert events into the Zeitgeist log without a160 * Note that the if you insert events into the Zeitgeist log without a
161 * timestamp set the Zeiteist daemon will automatically assign the timestamp161 * timestamp set the Zeiteist daemon will automatically assign the timestamp
162162
=== modified file 'src/zeitgeist-timerange.c'
--- src/zeitgeist-timerange.c 2010-04-22 12:31:21 +0000
+++ src/zeitgeist-timerange.c 2010-06-17 14:14:24 +0000
@@ -112,7 +112,7 @@
112 GTimeVal tv;112 GTimeVal tv;
113113
114 g_get_current_time (&tv);114 g_get_current_time (&tv);
115 time_range = zeitgeist_time_range_new (ZEITGEIST_GTIMEVAL_TO_TIMESTAMP (&tv),115 time_range = zeitgeist_time_range_new (zeitgeist_timestamp_from_timeval (&tv),
116 G_MAXINT64);116 G_MAXINT64);
117117
118 return time_range;118 return time_range;
@@ -132,7 +132,7 @@
132132
133 g_get_current_time (&tv);133 g_get_current_time (&tv);
134 time_range =134 time_range =
135 zeitgeist_time_range_new (0, ZEITGEIST_GTIMEVAL_TO_TIMESTAMP (&tv));135 zeitgeist_time_range_new (0, zeitgeist_timestamp_from_timeval (&tv));
136136
137 return time_range;137 return time_range;
138}138}
@@ -204,8 +204,8 @@
204204
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);
206206
207 ZEITGEIST_TIMESTAMP_TO_GTIMEVAL (zeitgeist_time_range_get_start (time_range),207 zeitgeist_timestamp_to_timeval (zeitgeist_time_range_get_start (time_range),
208 &tv);208 &tv);
209 return g_time_val_to_iso8601 (&tv);209 return g_time_val_to_iso8601 (&tv);
210}210}
211211
@@ -227,7 +227,7 @@
227227
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);
229229
230 ZEITGEIST_TIMESTAMP_TO_GTIMEVAL (zeitgeist_time_range_get_end (time_range),230 zeitgeist_timestamp_to_timeval (zeitgeist_time_range_get_end (time_range),
231 &tv);231 &tv);
232 return g_time_val_to_iso8601 (&tv);232 return g_time_val_to_iso8601 (&tv);
233}233}
234234
=== modified file 'src/zeitgeist-timerange.h'
--- src/zeitgeist-timerange.h 2010-06-16 13:17:00 +0000
+++ src/zeitgeist-timerange.h 2010-06-17 14:14:24 +0000
@@ -49,30 +49,6 @@
49 GInitiallyUnowned parent_instance;49 GInitiallyUnowned parent_instance;
50};50};
5151
52/**
53 * ZEITGEIST_GTIMEVAL_TO_TIMESTAMP:
54 * @gtimeval: A #GTimeVal instance
55 *
56 * Returns: A #gint64 with the total number of milliseconds since the Unix Epoch
57 */
58#define ZEITGEIST_GTIMEVAL_TO_TIMESTAMP(gtimeval) \
59 (((gint64)(gtimeval)->tv_sec)*1000 + ((gint64)(gtimeval)->tv_usec)/1000)
60
61/**
62 * ZEITGEIST_TIMESTAMP_TO_GTIMEVAL:
63 * @timestamp: A #gint64 with a number of milliseconds since the Unix Epoch
64 * @gtimeval: A #GTimeVal instance to store the result in
65 *
66 * Write a Zeitgeist timestamp to a #GTimeVal instance. Note that Zeitgeist
67 * uses only a millisecond resolution for where #GTimeVal uses a microsecond
68 * resolution, meaning that the lower three digits of @gtimeval.tv_usec will
69 * be 0.
70 *
71 * Returns: Nothing. The result is stored in @gtimeval
72 */
73#define ZEITGEIST_TIMESTAMP_TO_GTIMEVAL(systime, gtimeval) \
74 ((gtimeval)->tv_sec = systime/1000, (gtimeval)->tv_usec = (systime%1000)*1000)
75
76GType zeitgeist_time_range_get_type (void);52GType zeitgeist_time_range_get_type (void);
7753
78ZeitgeistTimeRange*54ZeitgeistTimeRange*
7955
=== added file 'src/zeitgeist-timestamp.c'
--- src/zeitgeist-timestamp.c 1970-01-01 00:00:00 +0000
+++ src/zeitgeist-timestamp.c 2010-06-17 14:14:24 +0000
@@ -0,0 +1,194 @@
1/*
2 * Copyright (C) 2010 Canonical, Ltd.
3 *
4 * This library is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License
6 * version 3.0 as published by the Free Software Foundation.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License version 3.0 for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library. If not, see
15 * <http://www.gnu.org/licenses/>.
16 *
17 * Authored by
18 * Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
19 */
20
21#include "zeitgeist-timerange.h"
22
23/**
24 * SECTION:zeitgeist-timestamp
25 * @short_description: Convenience functions for dealing with timestamps and dates
26 * @include: zeitgeist.h
27 *
28 * A suite of convenience functions for dealing with timestamps and dates.
29 *
30 * Zeitgeist timestamps are represented as #gint64<!-- -->s with the number
31 * of milliseconds since the Unix Epoch.
32 */
33#if HAVE_CONFIG_H
34#include <config.h>
35#endif
36
37#include "zeitgeist-timestamp.h"
38
39/**
40 * zeitgeist_timestamp_from_timeval:
41 * @tv: A #GTimeVal instance
42 *
43 * Returns: A #gint64 with the total number of milliseconds since the Unix Epoch
44 */
45gint64
46zeitgeist_timestamp_from_timeval (GTimeVal *tv)
47{
48 g_return_if_fail (tv != NULL);
49
50 return (((gint64)tv->tv_sec)*1000 + ((gint64)tv->tv_usec)/1000);
51}
52
53/**
54 * zeitgeist_timestamp_to_timeval:
55 * @timestamp: A #gint64 with a number of milliseconds since the Unix Epoch
56 * @tv: A #GTimeVal instance to store the result in
57 *
58 * Write a Zeitgeist timestamp to a #GTimeVal instance. Note that Zeitgeist
59 * uses only a millisecond resolution for where #GTimeVal uses a microsecond
60 * resolution, meaning that the lower three digits of @tv.tv_usec will
61 * be 0.
62 *
63 * Returns: Nothing. The result is stored in @tv
64 */
65void
66zeitgeist_timestamp_to_timeval (gint64 timestamp, GTimeVal *tv)
67{
68 g_return_if_fail (tv != NULL);
69
70 tv->tv_sec = timestamp / 1000;
71 tv->tv_usec = (timestamp % 1000) * 1000;
72}
73
74/**
75 * zeitgeist_timestamp_for_now:
76 *
77 * Get the timestamp for the current system time
78 *
79 * Returns: The timestamp for the current system time. Ie. the number of
80 * milliseconds since the Unix Epoch
81 */
82gint64
83zeitgeist_timestamp_for_now (void)
84{
85 GTimeVal tv;
86
87 g_get_current_time (&tv);
88 return zeitgeist_timestamp_from_timeval (&tv);
89}
90
91/**
92 * zeitgeist_timestamp_from_iso8601:
93 * @datetime: A string containing an iso8601 conforming datetime specification
94 *
95 * Parse a timestamp from a ISO8601 encoded string.
96 *
97 * Returns: The timestamp represented by @datetime, or -1 on failure to parse
98 * @datetime
99 */
100gint64
101zeitgeist_timestamp_from_iso8601 (const gchar *datetime)
102{
103 GTimeVal tv;
104
105 g_return_if_fail (datetime != NULL);
106
107 if (g_time_val_from_iso8601 (datetime, &tv))
108 return zeitgeist_timestamp_from_timeval (&tv);
109 else
110 return -1;
111}
112
113/**
114 * zeitgeist_timestamp_to_iso8601:
115 * @timestamp: A Zeitgeist timestamp in ms since the Epoch
116 *
117 * Convert a timestamp to a human readable ISO8601 format
118 *
119 * Returns: A newly allocated string containing the ISO8601 format of
120 * @timestamp. Free with g_free().
121 */
122gchar*
123zeitgeist_timestamp_to_iso8601 (gint64 timestamp)
124{
125 GTimeVal tv;
126
127 zeitgeist_timestamp_to_timeval (timestamp, &tv);
128 return g_time_val_to_iso8601 (&tv);
129}
130
131/**
132 * zeitgeist_timestamp_from_date:
133 * @date: A #GDate to convert
134 *
135 * Convert a #GDate to a Zeitgeist timestamp.
136 *
137 * Returns: @date as a timestamp in milliseconds since the Epoch
138 */
139gint64
140zeitgeist_timestamp_from_date (GDate *date)
141{
142 g_return_val_if_fail (date != NULL, -1);
143
144 gint64 julian = g_date_get_julian (date);
145
146 gint64 foo = ZEITGEIST_TIMESTAMP_YEAR;
147
148 return julian*ZEITGEIST_TIMESTAMP_DAY - 1969*ZEITGEIST_TIMESTAMP_YEAR;
149}
150
151/**
152 * zeitgeist_timestamp_from_dmy:
153 * @day: The day of the month represented as a #GDateDay
154 * @month: The month of the year represented as a #GDateMonth
155 * @year: The year represented as a #GDateYear
156 *
157 * Convert a day, month, year tuple into a Zeitgeist timestamp
158 *
159 * Returns: Input data as a timestamp in milliseconds since the Epoch or
160 * -1 in case the provided data does not constitute a valid date
161 */
162gint64
163zeitgeist_timestamp_from_dmy (GDateDay day,
164 GDateMonth month,
165 GDateYear year)
166{
167 GDate date = { 0 };
168
169 g_return_val_if_fail (g_date_valid_dmy (day, month, year), -1);
170
171 g_date_set_dmy (&date, day, month, year);
172 return zeitgeist_timestamp_from_date (&date);
173}
174
175/**
176 * zeitgeist_timestamp_to_date:
177 * @timestamp: The Zeitgeist timestamp to convert to a #GDate
178 * @date: The place to store the result in. Must be non-%NULL
179 *
180 * Write a timestamp to a #GDate structure
181 *
182 * Returns: Nothing. The return value is written to @date
183 */
184void
185zeitgeist_timestamp_to_date (gint64 timestamp,
186 GDate *date)
187{
188 GTimeVal tv;
189
190 g_return_if_fail (date != NULL);
191
192 zeitgeist_timestamp_to_timeval (timestamp, &tv);
193 g_date_set_time_val (date, &tv);
194}
0195
=== added file 'src/zeitgeist-timestamp.h'
--- src/zeitgeist-timestamp.h 1970-01-01 00:00:00 +0000
+++ src/zeitgeist-timestamp.h 2010-06-17 14:14:24 +0000
@@ -0,0 +1,100 @@
1/*
2 * Copyright (C) 2010 Canonical, Ltd.
3 *
4 * This library is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License
6 * version 3.0 as published by the Free Software Foundation.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License version 3.0 for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library. If not, see
15 * <http://www.gnu.org/licenses/>.
16 *
17 * Authored by
18 * Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
19 */
20
21#if !defined (_ZEITGEIST_H_INSIDE_) && !defined (ZEITGEIST_COMPILATION)
22#error "Only <zeitgeist.h> can be included directly."
23#endif
24
25#ifndef _ZEITGEIST_TIMESTAMP_H_
26#define _ZEITGEIST_TIMESTaMP_H_
27
28#include <glib.h>
29
30G_BEGIN_DECLS
31
32/**
33 * ZEITGEIST_TIMESTAMP_SECOND:
34 *
35 * A second represented as a Zeitgeist timestamp (ie. 1000ms)
36 */
37#define ZEITGEIST_TIMESTAMP_SECOND 1000LL
38
39/**
40 * ZEITGEIST_TIMESTAMP_MINUTE:
41 *
42 * A minute represented as a Zeitgeist timestamp (ie. 60000ms)
43 */
44#define ZEITGEIST_TIMESTAMP_MINUTE 60000LL
45
46/**
47 * ZEITGEIST_TIMESTAMP_HOUR:
48 *
49 * An hour represented as a Zeitgeist timestamp (ie. 3600000ms)
50 */
51#define ZEITGEIST_TIMESTAMP_HOUR 3600000LL
52
53/**
54 * ZEITGEIST_TIMESTAMP_DAY:
55 *
56 * A day represented as a Zeitgeist timestamp (ie. 86400000ms)
57 */
58#define ZEITGEIST_TIMESTAMP_DAY 86400000LL
59
60/**
61 * ZEITGEIST_TIMESTAMP_WEEK:
62 *
63 * A week represented as a Zeitgeist timestamp (ie. 604800000ms)
64 */
65#define ZEITGEIST_TIMESTAMP_WEEK 604800000LL
66
67/**
68 * ZEITGEIST_TIMESTAMP_YEAR:
69 *
70 * A year represented as a Zeitgeist timestamp (ie. 31556952000ms).
71 * Be warned that a year is not 365 days, but in fact 365.2425 days to
72 * account for leap years.
73 */
74#define ZEITGEIST_TIMESTAMP_YEAR 31556952000LL
75
76gint64 zeitgeist_timestamp_for_now (void);
77
78gint64 zeitgeist_timestamp_from_timeval (GTimeVal *tv);
79
80void zeitgeist_timestamp_to_timeval (gint64 timestamp,
81 GTimeVal *tv);
82
83gint64 zeitgeist_timestamp_from_iso8601 (const gchar *datetime);
84
85gchar* zeitgeist_timestamp_to_iso8601 (gint64 timestamp);
86
87gint64 zeitgeist_timestamp_from_date (GDate *date);
88
89gint64 zeitgeist_timestamp_from_dmy (GDateDay day,
90 GDateMonth month,
91 GDateYear year);
92
93void zeitgeist_timestamp_to_date (gint64 timestamp,
94 GDate *date);
95
96
97
98G_END_DECLS
99
100#endif /* _ZEITGEIST_TIMESTAMP_H_ */
0101
=== modified file 'src/zeitgeist.h'
--- src/zeitgeist.h 2010-06-09 20:38:14 +0000
+++ src/zeitgeist.h 2010-06-17 14:14:24 +0000
@@ -35,6 +35,7 @@
35#include <zeitgeist-result-set.h>35#include <zeitgeist-result-set.h>
36#include <zeitgeist-subject.h>36#include <zeitgeist-subject.h>
37#include <zeitgeist-timerange.h>37#include <zeitgeist-timerange.h>
38#include <zeitgeist-timestamp.h>
3839
39#undef _ZEITGEIST_H_INSIDE_40#undef _ZEITGEIST_H_INSIDE_
4041
4142
=== modified file 'tests/Makefile.am'
--- tests/Makefile.am 2010-06-10 10:19:33 +0000
+++ tests/Makefile.am 2010-06-17 14:14:24 +0000
@@ -34,6 +34,10 @@
34test_timerange_SOURCES = test-timerange.c $(helper_sources)34test_timerange_SOURCES = test-timerange.c $(helper_sources)
35test_timerange_LDADD = $(zeitgeist_libs)35test_timerange_LDADD = $(zeitgeist_libs)
3636
37TEST_PROGS += test-timestamp
38test_timestamp_SOURCES = test-timestamp.c $(helper_sources)
39test_timestamp_LDADD = $(zeitgeist_libs)
40
37TEST_PROGS += test-monitor41TEST_PROGS += test-monitor
38test_monitor_SOURCES = test-monitor.c $(helper_sources)42test_monitor_SOURCES = test-monitor.c $(helper_sources)
39test_monitor_LDADD = $(zeitgeist_libs)43test_monitor_LDADD = $(zeitgeist_libs)
4044
=== added file 'tests/test-timestamp.c'
--- tests/test-timestamp.c 1970-01-01 00:00:00 +0000
+++ tests/test-timestamp.c 2010-06-17 14:14:24 +0000
@@ -0,0 +1,96 @@
1/*
2 * Copyright (C) 2010 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
17 *
18 */
19
20#include <glib.h>
21#include <glib-object.h>
22#include "zeitgeist-timestamp.h"
23
24typedef struct
25{
26
27} Fixture;
28
29static void setup (Fixture *fix, gconstpointer data);
30static void teardown (Fixture *fix, gconstpointer data);
31
32static void
33setup (Fixture *fix, gconstpointer data)
34{
35
36}
37
38static void
39teardown (Fixture *fix, gconstpointer data)
40{
41
42}
43
44static void
45test_from_iso8601 (Fixture *fix, gconstpointer data)
46{
47 const gchar *orig = "2010-06-17T00:00:00Z";
48 gint64 from_iso = zeitgeist_timestamp_from_iso8601 (orig);
49 gchar *d = zeitgeist_timestamp_to_iso8601 (from_iso);
50
51 g_assert_cmpstr (orig, ==, d);
52 g_free (d);
53}
54
55static void
56test_inc_year (Fixture *fix, gconstpointer data)
57{
58 gchar *d = zeitgeist_timestamp_to_iso8601 (ZEITGEIST_TIMESTAMP_YEAR);
59
60 // Since ZEITGEIST_TIMESTAMP_YEAR accounts for leap years we wont exactly
61 // match "1971-01-01T00:00:00Z" on the hour
62 g_assert (g_str_has_prefix (d, "1971-01-01T"));
63 g_free (d);
64}
65
66static void
67test_from_date (Fixture *fix, gconstpointer data)
68{
69 GDate date = { 0 };
70
71 g_date_set_dmy (&date, 25, G_DATE_JUNE, 2000);
72 gint64 from_date = zeitgeist_timestamp_from_date (&date);
73
74 gchar *d = zeitgeist_timestamp_to_iso8601 (from_date);
75
76 // Since ZEITGEIST_TIMESTAMP_YEAR accounts for leap years we wont exactly
77 // match "2000-06-25T00:00:00Z" on the hour
78 g_assert (g_str_has_prefix (d, "2000-06-25T"));
79}
80
81int
82main (int argc,
83 char *argv[])
84{
85 g_type_init ();
86 g_test_init (&argc, &argv, NULL);
87
88 g_test_add ("/Zeitgeist/TimeRange/FromISO8601", Fixture, NULL,
89 setup, test_from_iso8601, teardown);
90 g_test_add ("/Zeitgeist/TimeRange/IncrementYear", Fixture, NULL,
91 setup, test_inc_year, teardown);
92 g_test_add ("/Zeitgeist/TimeRange/FromDate", Fixture, NULL,
93 setup, test_from_date, teardown);
94
95 return g_test_run();
96}
0\ No newline at end of file97\ No newline at end of file

Subscribers

People subscribed via source and target branches