aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/xep/0082_date_time_profiles.vala
blob: 32d4d3ac722ab1dcc47f5a31f3da3fa525359bd2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
namespace Xmpp.Xep.DateTimeProfiles {

public DateTime? parse_string(string time_string) {
    // TODO with glib >= 2.56
    // return new DateTime.from_iso8601(time_string, null);

    TimeVal time_val = 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) {
    // TODO with glib >= 2.62
    // return time.to_utc().format_iso8601().to_string();

    return time.to_utc().format("%Y-%m-%dT%H:%M:%SZ");
}

}