2 using System
.Globalization
;
5 namespace Search
.Tiles
{
7 public struct TileGroupInfo
{
8 public TileGroup Group
;
12 public TileGroupInfo (TileGroup
group, string name
, int rows
)
20 public static class Utils
{
22 public static TileGroupInfo
[] GroupInfo
= new TileGroupInfo
[] {
23 new TileGroupInfo (TileGroup
.Application
,
24 Catalog
.GetString ("Applications"), 1),
25 new TileGroupInfo (TileGroup
.Contact
,
26 Catalog
.GetString ("Contacts"), 2),
27 new TileGroupInfo (TileGroup
.Calendar
,
28 Catalog
.GetString ("Calendar Events"), 2),
29 new TileGroupInfo (TileGroup
.Folder
,
30 Catalog
.GetString ("Folders"), 2),
31 new TileGroupInfo (TileGroup
.Image
,
32 Catalog
.GetString ("Images"), 2),
33 new TileGroupInfo (TileGroup
.Audio
,
34 Catalog
.GetString ("Audio"), 2),
35 new TileGroupInfo (TileGroup
.Video
,
36 Catalog
.GetString ("Video"), 2),
37 new TileGroupInfo (TileGroup
.Documents
,
38 Catalog
.GetString ("Documents"), 2),
39 new TileGroupInfo (TileGroup
.Conversations
,
40 Catalog
.GetString ("Conversations"), 5),
41 new TileGroupInfo (TileGroup
.Website
,
42 Catalog
.GetString ("Websites"), 2),
43 new TileGroupInfo (TileGroup
.Feed
,
44 Catalog
.GetString ("News Feeds"), 2),
45 new TileGroupInfo (TileGroup
.Archive
,
46 Catalog
.GetString ("Archives"), 2),
49 public static ScopeType
TileGroupToScopeType (TileGroup
group)
53 case TileGroup
.Application
:
54 return ScopeType
.Applications
;
56 case TileGroup
.Calendar
:
57 return ScopeType
.Calendar
;
59 case TileGroup
.Contact
:
60 return ScopeType
.Contacts
;
62 // This TileGroup exists but does not seem to be used
63 // case TileGroup.Folder:
64 case TileGroup
.Documents
:
65 return ScopeType
.Documents
;
67 case TileGroup
.Conversations
:
68 return ScopeType
.Conversations
;
71 return ScopeType
.Images
;
74 return ScopeType
.Media
;
77 return ScopeType
.Media
;
79 case TileGroup
.Folder
:
80 return ScopeType
.Folders
;
82 case TileGroup
.Website
:
83 return ScopeType
.Websites
;
86 return ScopeType
.Feeds
;
88 case TileGroup
.Archive
:
89 return ScopeType
.Archives
;
93 Console
.WriteLine ("Error: Could not find ScopeType for Group: {0}",group);
94 return ScopeType
.Nothing
;
98 public static DateTime
ParseTimestamp (string timestamp
)
101 dt
= new DateTime (Int32
.Parse (timestamp
.Substring (0, 4)),
102 Int32
.Parse (timestamp
.Substring (4, 2)),
103 Int32
.Parse (timestamp
.Substring (6, 2)),
104 Int32
.Parse (timestamp
.Substring (8, 2)),
105 Int32
.Parse (timestamp
.Substring (10, 2)),
106 Int32
.Parse (timestamp
.Substring (12, 2)));
110 private static DateTimeFormatInfo DateTimeFormat
= CultureInfo
.CurrentCulture
.DateTimeFormat
;
111 private static string ShortMonthDayPattern
= DateTimeFormat
.MonthDayPattern
.Replace ("MMMM", "MMM");
112 private static string ShortYearMonthPattern
= DateTimeFormat
.YearMonthPattern
.Replace ("MMMM", "MMM");
113 private static string MonthDayPattern
= DateTimeFormat
.MonthDayPattern
;
114 private static string LongDatePattern
= DateTimeFormat
.LongDatePattern
.Replace ("dddd, ", "").Replace ("dddd ", "").Replace (" dddd", "");
116 private static string NiceDatePattern (DateTime dt
, string month_day_pattern
, string year_month_pattern
)
121 dt
= dt
.ToLocalTime ().Date
;
122 DateTime today
= DateTime
.Today
;
123 TimeSpan one_day
= new TimeSpan (TimeSpan
.TicksPerDay
);
125 if (dt
== today
- one_day
)
126 return Catalog
.GetString ("Yesterday");
127 else if (dt
== today
)
128 return Catalog
.GetString ("Today");
129 else if (dt
== today
+ one_day
)
130 return Catalog
.GetString ("Tomorrow");
139 if (span
.TotalDays
< 7)
140 return dt
.ToString ("dddd"); // "Tuesday"
141 else if (dt
.Year
== today
.Year
|| span
.TotalDays
< 180)
142 return dt
.ToString (month_day_pattern
);
144 return dt
.ToString (year_month_pattern
);
147 public static string NiceShortDate (string timestamp
)
152 dt
= ParseTimestamp (timestamp
);
157 return NiceShortDate (dt
);
160 public static string NiceShortDate (DateTime dt
)
162 // "Jul 4" and "Jan 2001", respectively.
163 return NiceDatePattern (dt
, ShortMonthDayPattern
, ShortYearMonthPattern
);
166 public static string NiceLongDate (string timestamp
)
171 dt
= ParseTimestamp (timestamp
);
176 return NiceLongDate (dt
);
179 public static string NiceLongDate (DateTime dt
)
181 // "July 4" and "January 7, 2001", respectively.
182 return NiceDatePattern (dt
, MonthDayPattern
, LongDatePattern
);
185 public static string NiceVeryLongDate (string timestamp
)
190 dt
= ParseTimestamp (timestamp
);
195 return NiceVeryLongDate (dt
);
198 public static string NiceVeryLongDate (DateTime dt
)
203 dt
= dt
.ToLocalTime ().Date
;
204 DateTime today
= DateTime
.Today
;
205 TimeSpan one_day
= new TimeSpan (TimeSpan
.TicksPerDay
);
207 if (dt
== today
- one_day
)
208 return Catalog
.GetString ("Yesterday");
209 else if (dt
== today
)
210 return Catalog
.GetString ("Today");
211 else if (dt
== today
+ one_day
)
212 return Catalog
.GetString ("Tomorrow");
225 if (span
.TotalDays
< 7)
226 return dt
.ToString ("dddd"); // "Tuesday"
227 else if (span
.TotalDays
< 30 && ! future
)
228 return String
.Format (Catalog
.GetPluralString ("{0} week ago", "{0} weeks ago", span
.Days
/ 7) + " ({1:MMMM d, yyyy})", span
.Days
/ 7, dt
);
229 else if (span
.TotalDays
< 30 && future
)
230 return String
.Format (Catalog
.GetPluralString ("In {0} week", "In {0} weeks", span
.Days
/ 7) + " {1:MMMM d, yyyy})", span
.Days
/ 7, dt
);
231 else if (span
.TotalDays
< 365 + 180 && ! future
) // Let's say a year and a half to stop saying months
232 return String
.Format (Catalog
.GetPluralString ("{0} month ago", "{0} months ago", span
.Days
/ 30) + " ({1:MMMM d, yyyy})", span
.Days
/ 30, dt
);
233 else if (span
.TotalDays
< 365 + 180 && future
)
234 return String
.Format (Catalog
.GetPluralString ("In {0} month", "In {0} months", span
.Days
/ 30) + " ({1:MMMM d, yyyy})", span
.Days
/ 30, dt
);
236 return String
.Format (Catalog
.GetPluralString ("{0} year ago", "{0} years ago", span
.Days
/ 365) + " ({1:MMMM d, yyyy})", span
.Days
/ 365, dt
);
238 return String
.Format (Catalog
.GetPluralString ("In {0} year", "In {0} years", span
.Days
/ 365) + " ({1:MMMM d, yyyy})", span
.Days
/ 365, dt
);