~ubuntu-branches/ubuntu/precise/empathy/precise-proposed-201205180810

« back to all changes in this revision

Viewing changes to libempathy/empathy-time.c

  • Committer: Bazaar Package Importer
  • Author(s): Brian Curtis, Brian Curtis, Ken VanDine
  • Date: 2011-06-01 10:35:24 UTC
  • mfrom: (1.1.70 upstream) (6.3.44 experimental)
  • Revision ID: james.westby@ubuntu.com-20110601103524-wx3wgp71394730jt
Tags: 3.1.1-1ubuntu1
[ Brian Curtis ]
* Merge with Debian experimental, remaining Ubuntu changes:
* debian/control:
  - Drop geoclue/mapping build-depends (they are in Universe)
  - Add Vcz-Bzr link
  - Add Suggests on telepathy-idle
  - Bump telepathy-butterfly, telepathy-haze to recommends
  - Don't recommend the freedesktop sound theme we have an ubuntu one
  - Add build depend for libunity-dev
* debian/rules:
  - Use autoreconf.mk
  - Disable map and location
* debian/empathy.install:
  - Install message indicator configuration
* debian/indicators/empathy:
  - Message indicator configuration
* debian/patches/01_lpi.patch:
  - Add Launchpad integration
* debian/patches/10_use_notify_osd_icons.patch:
  - Use the notify-osd image for new messages
* debian/patches/34_start_raised_execpt_in_session.patch
  - If not started with the session, we should always raise
* debian/patches/36_chat_window_default_size.patch:
  - Make the default chat window size larger
* debian/patches/37_facebook_default.patch:
  - Make facebook the default chat account type
* debian/patches/38_lp_569289.patch
  - Set freenode as default IRC network for new IRC accounts 
* debian/patches/41_unity_launcher_progress.patch
  - Display file transfer progress in the unity launcher

[ Ken VanDine ]
* debian/control
  - build depend on libgcr-3-dev instead of libgcr-dev
  - dropped build depends for libindicate, we will use telepathy-indicator
  - Depend on dconf-gsettings-backend | gsettings-backend
  - Added a Recommends for telepathy-indicator
* +debian/empathy.gsettings-override
  - Added an override for notifications-focus
* debian/patches/series
  - commented out 23_idomessagedialog_for_voip_and_ft.patch, until ido has 
    been ported to gtk3

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
/* Note: EmpathyTime is always in UTC. */
33
33
 
34
 
time_t
 
34
gint64
35
35
empathy_time_get_current (void)
36
36
{
37
 
        return time (NULL);
38
 
}
39
 
 
40
 
time_t
41
 
empathy_time_get_local_time (struct tm *tm)
42
 
{
43
 
        const gchar *tz;
44
 
        time_t       t;
45
 
 
46
 
        tz = g_getenv ("TZ");
47
 
        g_setenv ("TZ", "", TRUE);
48
 
 
49
 
        tzset ();
50
 
 
51
 
        t = mktime (tm);
52
 
 
53
 
        if (tz) {
54
 
                g_setenv ("TZ", tz, TRUE);
55
 
        } else {
56
 
                g_unsetenv ("TZ");
57
 
        }
58
 
 
59
 
        tzset ();
60
 
 
61
 
        return t;
62
 
}
63
 
 
64
 
/* The format is: "20021209T23:51:30" and is in UTC. 0 is returned on
65
 
 * failure. The alternative format "20021209" is also accepted.
66
 
 */
67
 
time_t
68
 
empathy_time_parse (const gchar *str)
69
 
{
70
 
        struct tm tm;
71
 
        gint      year, month;
72
 
        gint      n_parsed;
73
 
 
74
 
        memset (&tm, 0, sizeof (struct tm));
75
 
 
76
 
        n_parsed = sscanf (str, "%4d%2d%2dT%2d:%2d:%2d",
77
 
                    &year, &month, &tm.tm_mday, &tm.tm_hour,
78
 
                           &tm.tm_min, &tm.tm_sec);
79
 
        if (n_parsed != 3 && n_parsed != 6) {
80
 
                return 0;
81
 
        }
82
 
 
83
 
        tm.tm_year = year - 1900;
84
 
        tm.tm_mon = month - 1;
85
 
        tm.tm_isdst = -1;
86
 
 
87
 
        return empathy_time_get_local_time (&tm);
 
37
        GDateTime *now;
 
38
        gint64 result;
 
39
 
 
40
        now = g_date_time_new_now_utc ();
 
41
        result = g_date_time_to_unix (now);
 
42
        g_date_time_unref (now);
 
43
 
 
44
        return result;
88
45
}
89
46
 
90
47
/* Converts the UTC timestamp to a string, also in UTC. Returns NULL on failure. */
91
48
gchar *
92
 
empathy_time_to_string_utc (time_t       t,
 
49
empathy_time_to_string_utc (gint64       t,
93
50
                            const gchar *format)
94
51
{
95
 
        gchar      stamp[128];
96
 
        struct tm *tm;
 
52
        GDateTime *d;
 
53
        char *result;
97
54
 
98
55
        g_return_val_if_fail (format != NULL, NULL);
99
56
 
100
 
        tm = gmtime (&t);
101
 
        if (strftime (stamp, sizeof (stamp), format, tm) == 0) {
102
 
                return NULL;
103
 
        }
 
57
        d = g_date_time_new_from_unix_utc (t);
 
58
        result = g_date_time_format (d, format);
 
59
        g_date_time_unref (d);
104
60
 
105
 
        return g_strdup (stamp);
 
61
        return result;
106
62
}
107
63
 
108
64
/* Converts the UTC timestamp to a string, in local time. Returns NULL on failure. */
109
65
gchar *
110
 
empathy_time_to_string_local (time_t       t,
 
66
empathy_time_to_string_local (gint64 t,
111
67
                              const gchar *format)
112
68
{
113
 
        gchar      stamp[128];
114
 
        struct tm *tm;
 
69
        GDateTime *d, *local;
 
70
        gchar *result;
115
71
 
116
72
        g_return_val_if_fail (format != NULL, NULL);
117
73
 
118
 
        tm = localtime (&t);
119
 
        if (strftime (stamp, sizeof (stamp), format, tm) == 0) {
120
 
                return NULL;
121
 
        }
122
 
 
123
 
        return g_strdup (stamp);
 
74
        d = g_date_time_new_from_unix_utc (t);
 
75
        local = g_date_time_to_local (d);
 
76
        g_date_time_unref (d);
 
77
 
 
78
        result = g_date_time_format (local, format);
 
79
        g_date_time_unref (local);
 
80
 
 
81
        return result;
124
82
}
125
83
 
126
84
gchar  *
127
 
empathy_time_to_string_relative (time_t then)
 
85
empathy_time_to_string_relative (gint64 t)
128
86
{
129
 
        time_t now;
 
87
        GDateTime *now, *then;
130
88
        gint   seconds;
131
 
 
132
 
        now = time (NULL);
133
 
        seconds = now - then;
 
89
        GTimeSpan delta;
 
90
        gchar *result;
 
91
 
 
92
        now = g_date_time_new_now_utc ();
 
93
        then = g_date_time_new_from_unix_utc (t);
 
94
 
 
95
        delta = g_date_time_difference (now, then);
 
96
        seconds = delta / G_TIME_SPAN_SECOND;
134
97
 
135
98
        if (seconds > 0) {
136
99
                if (seconds < 60) {
137
 
                        return g_strdup_printf (ngettext ("%d second ago",
 
100
                        result = g_strdup_printf (ngettext ("%d second ago",
138
101
                                "%d seconds ago", seconds), seconds);
139
102
                }
140
103
                else if (seconds < (60 * 60)) {
141
104
                        seconds /= 60;
142
 
                        return g_strdup_printf (ngettext ("%d minute ago",
 
105
                        result = g_strdup_printf (ngettext ("%d minute ago",
143
106
                                "%d minutes ago", seconds), seconds);
144
107
                }
145
108
                else if (seconds < (60 * 60 * 24)) {
146
109
                        seconds /= 60 * 60;
147
 
                        return g_strdup_printf (ngettext ("%d hour ago",
 
110
                        result = g_strdup_printf (ngettext ("%d hour ago",
148
111
                                "%d hours ago", seconds), seconds);
149
112
                }
150
113
                else if (seconds < (60 * 60 * 24 * 7)) {
151
114
                        seconds /= 60 * 60 * 24;
152
 
                        return g_strdup_printf (ngettext ("%d day ago",
 
115
                        result = g_strdup_printf (ngettext ("%d day ago",
153
116
                                "%d days ago", seconds), seconds);
154
117
                }
155
118
                else if (seconds < (60 * 60 * 24 * 30)) {
156
119
                        seconds /= 60 * 60 * 24 * 7;
157
 
                        return g_strdup_printf (ngettext ("%d week ago",
 
120
                        result = g_strdup_printf (ngettext ("%d week ago",
158
121
                                "%d weeks ago", seconds), seconds);
159
122
                }
160
123
                else {
161
124
                        seconds /= 60 * 60 * 24 * 30;
162
 
                        return g_strdup_printf (ngettext ("%d month ago",
 
125
                        result = g_strdup_printf (ngettext ("%d month ago",
163
126
                                "%d months ago", seconds), seconds);
164
127
                }
165
128
        }
166
129
        else {
167
 
                return g_strdup (_("in the future"));
 
130
                result = g_strdup (_("in the future"));
168
131
        }
 
132
 
 
133
        g_date_time_unref (now);
 
134
        g_date_time_unref (then);
 
135
 
 
136
        return result;
169
137
}