21196ffe654d7df66c7d0138a18efddf1bec7031
[WhereAmI.git] / src / org / average / whereami / SayWhen.java
1 package org.average.whereami;
2
3 import android.content.res.Resources;
4 import android.text.format.Time;
5 import android.util.Log;
6
7 public class SayWhen {
8
9         private String s_at;
10         private String yesterday;
11
12         public SayWhen(final Resources res) {
13                 s_at = res.getString(R.string.s_at);
14                 yesterday = res.getString(R.string.yesterday);
15         }
16
17         public String say(Long when) {
18                 Long now = System.currentTimeMillis();
19                 Time tnow = new Time();
20                 tnow.set(now);
21                 Time twhen = new Time();
22                 twhen.set(when);
23                 Boolean datechange = tnow.monthDay != twhen.monthDay;
24                 Long hoursago = (System.currentTimeMillis() - when) / 3600000;
25                 if (hoursago > 24) {
26                         return s_at + twhen.format(" %H:%M %d/%m/%Y");
27                 } else if ((tnow.hour > 4 || hoursago > 12) && datechange) {
28                         return yesterday + " " + s_at + twhen.format(" %H:%M");
29                 } else {
30                         return s_at + twhen.format(" %H:%M");
31                 }
32         }
33 }