~mterry/+junk/u8.2

« back to all changes in this revision

Viewing changes to plugins/Utils/relativetimeformatter.cpp

  • Committer: Michael Terry
  • Date: 2014-11-17 14:56:04 UTC
  • mfrom: (1317.1.118 unity8)
  • Revision ID: michael.terry@canonical.com-20141117145604-96dn9p5nwkifq2f4
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
    }
75
75
 
76
76
    // did it happen yesterday?
77
 
    GDateTime* tomorrow = g_date_time_add_days(now, -1);
 
77
    GDateTime* yesterday = g_date_time_add_days(now, -1);
78
78
    gint tom_year, tom_month, tom_day;
 
79
    g_date_time_get_ymd(yesterday, &tom_year, &tom_month, &tom_day);
 
80
    g_date_time_unref(yesterday);
 
81
    if ((tom_year == time_year) && (tom_month == time_month) && (tom_day == time_day)) {
 
82
        return DATE_PROXIMITY_YESTERDAY;
 
83
    }
 
84
 
 
85
    // does it happen tomorrow?
 
86
    GDateTime* tomorrow = g_date_time_add_days(now, 1);
79
87
    g_date_time_get_ymd(tomorrow, &tom_year, &tom_month, &tom_day);
80
88
    g_date_time_unref(tomorrow);
81
89
    if ((tom_year == time_year) && (tom_month == time_month) && (tom_day == time_day)) {
82
 
        return DATE_PROXIMITY_YESTERDAY;
83
 
    }
84
 
 
85
 
    // does it happen tomorrow?
86
 
    if (prox == DATE_PROXIMITY_FAR)
87
 
    {
88
 
        GDateTime* tomorrow = g_date_time_add_days(now, 1);
89
 
 
90
 
        gint tom_year, tom_month, tom_day;
91
 
        g_date_time_get_ymd(tomorrow, &tom_year, &tom_month, &tom_day);
92
 
        g_date_time_unref(tomorrow);
93
 
        if ((tom_year == time_year) && (tom_month == time_month) && (tom_day == time_day)) {
94
 
            return DATE_PROXIMITY_TOMORROW;
95
 
        }
 
90
        return DATE_PROXIMITY_TOMORROW;
96
91
    }
97
92
 
98
93
    // does it happen this week?
99
 
    if (prox == DATE_PROXIMITY_FAR) {
100
 
        if (g_date_time_compare(time, now) < 0) {
101
 
            GDateTime* last_week = g_date_time_add_days(now, -6);
102
 
            GDateTime* last_week_bound = g_date_time_new_local(g_date_time_get_year(last_week),
103
 
                                                               g_date_time_get_month(last_week),
104
 
                                                               g_date_time_get_day_of_month(last_week),
105
 
                                                               0, 0, 0);
106
 
            if (g_date_time_compare(time, last_week_bound) >= 0)
107
 
                prox = DATE_PROXIMITY_LAST_WEEK;
108
 
 
109
 
            g_date_time_unref(last_week);
110
 
            g_date_time_unref(last_week_bound);
111
 
        } else {
112
 
            GDateTime* next_week = g_date_time_add_days(now, 6);
113
 
            GDateTime* next_week_bound = g_date_time_new_local(g_date_time_get_year(next_week),
114
 
                                                               g_date_time_get_month(next_week),
115
 
                                                               g_date_time_get_day_of_month(next_week),
116
 
                                                               23, 59, 59.9);
117
 
            if (g_date_time_compare(time, next_week_bound) <= 0)
118
 
                prox = DATE_PROXIMITY_NEXT_WEEK;
119
 
 
120
 
            g_date_time_unref(next_week);
121
 
            g_date_time_unref(next_week_bound);
122
 
        }
123
 
 
 
94
    if (g_date_time_compare(time, now) < 0) {
 
95
        GDateTime* last_week = g_date_time_add_days(now, -6);
 
96
        GDateTime* last_week_bound = g_date_time_new_local(g_date_time_get_year(last_week),
 
97
                                                           g_date_time_get_month(last_week),
 
98
                                                           g_date_time_get_day_of_month(last_week),
 
99
                                                           0, 0, 0);
 
100
        if (g_date_time_compare(time, last_week_bound) >= 0)
 
101
            prox = DATE_PROXIMITY_LAST_WEEK;
 
102
 
 
103
        g_date_time_unref(last_week);
 
104
        g_date_time_unref(last_week_bound);
 
105
    } else {
 
106
        GDateTime* next_week = g_date_time_add_days(now, 6);
 
107
        GDateTime* next_week_bound = g_date_time_new_local(g_date_time_get_year(next_week),
 
108
                                                           g_date_time_get_month(next_week),
 
109
                                                           g_date_time_get_day_of_month(next_week),
 
110
                                                           23, 59, 59.9);
 
111
        if (g_date_time_compare(time, next_week_bound) <= 0)
 
112
            prox = DATE_PROXIMITY_NEXT_WEEK;
 
113
 
 
114
        g_date_time_unref(next_week);
 
115
        g_date_time_unref(next_week_bound);
124
116
    }
125
117
 
126
118
    return prox;
250
242
 
251
243
QString RelativeTimeFormatter::format() const
252
244
{
253
 
    GDateTime* now = g_date_time_new_from_unix_utc(QDateTime::currentMSecsSinceEpoch() / 1000);
 
245
    GDateTime* now = g_date_time_new_now_local();
254
246
    if (!now) { return QString(); }
255
247
 
256
248
    GDateTime* then = g_date_time_new_from_unix_local(time());