~ubuntu-branches/ubuntu/trusty/unity-place-files/trusty

« back to all changes in this revision

Viewing changes to src/utils.vala

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-08-26 18:52:52 UTC
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20100826185252-rtxst6inf3chd7po
Tags: upstream-0.5.18
ImportĀ upstreamĀ versionĀ 0.5.18

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
      switch (month)
99
99
        {
100
100
          case DateMonth.BAD_MONTH:
101
 
            return "Invalid Month";
 
101
            return _("Invalid Month");
102
102
          case DateMonth.JANUARY:
103
 
            return "January";
 
103
            return _("January");
104
104
          case DateMonth.FEBRUARY:
105
 
            return "February";
 
105
            return _("February");
106
106
          case DateMonth.MARCH:
107
 
            return "March";
 
107
            return _("March");
108
108
          case DateMonth.APRIL:
109
 
            return "April";
 
109
            return _("April");
110
110
          case DateMonth.MAY:
111
 
            return "May";
 
111
            return _("May");
112
112
          case DateMonth.JUNE:
113
 
            return "June";
 
113
            return _("June");
114
114
          case DateMonth.JULY:
115
 
            return "July";
 
115
            return _("July");
116
116
          case DateMonth.AUGUST:
117
 
            return "August";
 
117
            return _("August");
118
118
          case DateMonth.SEPTEMBER:
119
 
            return "September";
 
119
            return _("September");
120
120
          case DateMonth.OCTOBER:
121
 
            return "October";
 
121
            return _("October");
122
122
          case DateMonth.NOVEMBER:
123
 
            return "November";
 
123
            return _("November");
124
124
          case DateMonth.DECEMBER:
125
 
            return "December";
 
125
            return _("December");
126
126
        }
127
127
        
128
128
      return "Internal Error";
129
129
    }
 
130
 
 
131
    public string get_day_name (DateWeekday weekday)
 
132
    {
 
133
      switch (weekday)
 
134
        {
 
135
        case GLib.DateWeekday.MONDAY:
 
136
          return _("Monday");
 
137
        case GLib.DateWeekday.TUESDAY:
 
138
          return  _("Tuesday");
 
139
        case GLib.DateWeekday.WEDNESDAY:
 
140
          return _("Wednesday");
 
141
        case GLib.DateWeekday.THURSDAY:
 
142
          return _("Thursday");
 
143
        case GLib.DateWeekday.FRIDAY:
 
144
          return _("Friday");
 
145
        case GLib.DateWeekday.SATURDAY:
 
146
          return _("Saturday");
 
147
        case GLib.DateWeekday.SUNDAY:
 
148
          return _("Sunday");
 
149
        default:
 
150
          return "Internal Error";
 
151
        }
 
152
    }
130
153
    
131
154
    /* Calculate the time group of the event returning the group id
132
155
     * of the group @event belongs to. It may be necessary for this method
133
156
     * to add a row to @groups_model if the group is one of the variadic
134
157
     * types such as */
135
 
    public uint get_time_group (Zeitgeist.Event event, Dee.Model groups_model)
 
158
    public uint get_time_group (Zeitgeist.Event event,
 
159
                                Dee.Model groups_model,
 
160
                                out string comment=null)
136
161
    {
137
162
      // FIXME: We need to calculate bounds of previous midnight, week, month etc
138
163
      //        This impl is just a quick hack to have something to show
139
164
      
140
165
      var t = event.get_timestamp ();
141
166
      var now = Timestamp.now ();
 
167
      var delta = now - t;
 
168
      
 
169
      debug (@"DELTA: $now - $t = $delta");
142
170
      
143
171
      /* Set limit to the previous midnight */
144
172
      var limit = Timestamp.prev_midnight (now);
145
173
      if (t > limit)
146
 
        return Group.TODAY;
 
174
        {
 
175
          /* Fuzzy hour match */
 
176
          var hour = Timestamp.HOUR;
 
177
 
 
178
          if (delta > hour * 7)
 
179
            comment = _("Earlier today");
 
180
          else if (delta > hour * 6)
 
181
            comment = _("Five hours ago");
 
182
          else if (delta > hour * 5)
 
183
            comment = _("Four hours ago");
 
184
          else if (delta > hour * 4)
 
185
            comment = _("Three hours ago");
 
186
          else if (delta > hour * 3)
 
187
            comment = _("Two hours ago");
 
188
          else if (delta > hour * 2)
 
189
            comment = _("1 hour ago");
 
190
          else
 
191
            comment = _("Past hour");
 
192
          
 
193
          return Group.TODAY;
 
194
        }
147
195
      else if (t > limit - Zeitgeist.Timestamp.DAY)
148
 
        return Group.YESTERDAY;
 
196
        {
 
197
          comment = _("Yesterday");
 
198
          return Group.YESTERDAY;
 
199
        }
149
200
      
150
201
      /* Set limit to start of calendar week (monday) */
151
202
      var date = Date();
152
203
      Timestamp.to_date (now, out date);
153
204
      limit = limit - (date.get_weekday() - 1)*Timestamp.DAY;
 
205
 
 
206
      /* Try and give the name of the day */
 
207
      var datethen = Date ();
 
208
      Timestamp.to_date (t, out datethen);
 
209
      comment = get_day_name (datethen.get_weekday ());
 
210
 
154
211
      if (t > limit)
155
212
        return Group.THIS_WEEK;
156
213
      else if (t > limit - Zeitgeist.Timestamp.WEEK)
160
217
      date.set_day (1);
161
218
      limit = Timestamp.from_date (date);
162
219
      if (t > limit)
163
 
        return Group.THIS_MONTH;
164
 
      
 
220
        {
 
221
          var days = datethen.days_between (date);
 
222
 
 
223
          /* Try and give a fuzzy weeks time */
 
224
          if (days < 7 * 3)
 
225
            comment = _("Three weeks ago");
 
226
          else if (days < 7 * 4)
 
227
            comment = _("A month ago");
 
228
          return Group.THIS_MONTH;
 
229
        }
 
230
 
 
231
      /* At this point let's just fall back to month name */
 
232
      comment = get_month_name (datethen.get_month ());
 
233
     
165
234
      /* Set limit to start of previous calendar month */
166
235
      date.subtract_months (1);
167
236
      limit = Timestamp.from_date (date);
168
237
      if (t > now - 6*30*Zeitgeist.Timestamp.DAY)
169
 
        return Group.PAST_SIX_MONTHS;
 
238
        {
 
239
          return Group.PAST_SIX_MONTHS;
 
240
        }
170
241
      
171
242
      /* Set limit to 1st pf January in the current year. We need to 
172
243
       * reset 'date' because date.subtract_months(1) above might have
176
247
      date.set_day (1);
177
248
      limit = Timestamp.from_date (date);
178
249
      if (t > limit)
179
 
        return Group.THIS_YEAR;
 
250
        {
 
251
          return Group.THIS_YEAR;
 
252
        }
180
253
      else
181
254
        return Group.LAST_YEAR;
182
255
    }