annotate UnixTimestamp.cs @ 11:ba9239164de2

Fixes #5 - Converting dictionary to array * Add genericed DictionaryToArrayConverter class to IBBoard utils
author IBBoard <dev@ibboard.co.uk>
date Sun, 04 Jan 2009 14:44:19 +0000
parents 961030992bd2
children 0352fa33ee8f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 using System;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 namespace IBBoard
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 /// <summary>
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 /// Summary description for UnixTimestamp.
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 /// </summary>
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 public class UnixTimestamp
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 private long stamp;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 private static DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0).ToUniversalTime();
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 public UnixTimestamp(DateTime date)
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 stamp = GetTimestamp(date);
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 public UnixTimestamp(long timestamp)
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 stamp = timestamp;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 public DateTime GetDate()
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 return unixEpoch.AddSeconds(stamp);
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 public DateTime GetDate(int timestamp)
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 return unixEpoch.AddSeconds(timestamp);
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 public long GetTimestamp()
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 return stamp;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 public static long GetTimestamp(DateTime date)
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 TimeSpan span = date.ToUniversalTime() - unixEpoch;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 return (long)span.TotalSeconds;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 }