Added hammock project to debug streaming issues
[pithos-ms-client] / trunk / hammock / src / net35 / Hammock.Tests / Helpers / TimeExtensions.cs
1 using System;
2
3 namespace Hammock.Tests.Helpers
4 {
5     internal static class TimeExtensions
6     {
7         public static TimeSpan Hours(this int hours)
8         {
9             return new TimeSpan(0, hours, 0, 0);
10         }
11
12         public static TimeSpan Minutes(this int minutes)
13         {
14             return new TimeSpan(0, 0, minutes, 0);
15         }
16
17         public static TimeSpan Seconds(this int seconds)
18         {
19             return new TimeSpan(0, 0, 0, seconds);
20         }
21
22         public static TimeSpan Milliseconds(this int milliseconds)
23         {
24             return new TimeSpan(0, 0, 0, 0, milliseconds);
25         }
26
27         public static DateTime Ago(this TimeSpan value)
28         {
29             return DateTime.UtcNow.Add(value.Negate());
30         }
31
32         public static DateTime FromNow(this TimeSpan value)
33         {
34             return new DateTime((DateTime.Now + value).Ticks);
35         }
36
37         public static DateTime FromUnixTime(this long seconds)
38         {
39             var time = new DateTime(1970, 1, 1);
40             time = time.AddSeconds(seconds);
41
42             return time.ToLocalTime();
43         }
44
45         public static long ToUnixTime(this DateTime dateTime)
46         {
47             var timeSpan = (dateTime - new DateTime(1970, 1, 1));
48             var timestamp = (long)timeSpan.TotalSeconds;
49
50             return timestamp;
51         }
52     }
53 }