aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-08-22 12:13:11 +0200
committerfiaxh <git@mx.ax.lt>2017-08-22 16:23:15 +0200
commit621e1e98cbc9b760ad4c8f79d8ca5c12107a63e8 (patch)
tree6e316006ba8984aaceee9b546d9afd0e3fe88d1e /xmpp-vala/src
parent4a4b5956c9b12bbfb583da1794ef0184e760ac33 (diff)
downloaddino-621e1e98cbc9b760ad4c8f79d8ca5c12107a63e8.tar.gz
dino-621e1e98cbc9b760ad4c8f79d8ca5c12107a63e8.zip
xmpp-vala: Improve time parsing
Diffstat (limited to 'xmpp-vala/src')
-rw-r--r--xmpp-vala/src/module/xep/0082_date_time_profiles.vala26
1 files changed, 4 insertions, 22 deletions
diff --git a/xmpp-vala/src/module/xep/0082_date_time_profiles.vala b/xmpp-vala/src/module/xep/0082_date_time_profiles.vala
index 5c09e4a6..8c7dffc1 100644
--- a/xmpp-vala/src/module/xep/0082_date_time_profiles.vala
+++ b/xmpp-vala/src/module/xep/0082_date_time_profiles.vala
@@ -1,32 +1,14 @@
namespace Xmpp.Xep.DateTimeProfiles {
public DateTime? parse_string(string time_string) {
- Regex DATETIME_REGEX = new Regex("""^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.(\d{3}))?(Z|((\+|\-)(\d{2})(:(\d{2}))?))$""");
- MatchInfo match_info;
- if (DATETIME_REGEX.match(time_string, RegexMatchFlags.ANCHORED, out match_info)) {
- int year = int.parse(match_info.fetch(1));
- int month = int.parse(match_info.fetch(2));
- int day = int.parse(match_info.fetch(3));
- int hour = int.parse(match_info.fetch(4));
- int minute = int.parse(match_info.fetch(5));
- int second = int.parse(match_info.fetch(6));
- DateTime datetime = new DateTime.utc(year, month, day, hour, minute, second);
- if (match_info.fetch(9) != "Z") {
- char plusminus = match_info.fetch(11)[0];
- int tz_hour = int.parse(match_info.fetch(12));
- int tz_minute = int.parse(match_info.fetch(13));
- if (plusminus == '-') {
- tz_hour *= -1;
- tz_minute *= -1;
- }
- datetime.add_hours(tz_hour);
- datetime.add_minutes(tz_minute);
- }
- return datetime;
+ TimeVal time_val = new TimeVal();
+ if (time_val.from_iso8601(time_string)) {
+ return new DateTime.from_unix_utc(time_val.tv_sec);
}
return null;
}
+
public string to_datetime(DateTime time) {
return time.to_utc().format("%Y-%m-%dT%H:%M:%SZ");
}