forked from yankooliveira/signals
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSerializableDateTime.cs
50 lines (44 loc) · 1004 Bytes
/
SerializableDateTime.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Simple helper class that allows you to serialize System.Type objects.
// Use it however you like, but crediting or even just contacting the author would be appreciated (Always
// nice to see people using your stuff!)
//
// Written by Bryan Keiren (http://www.bryankeiren.com)
using System;
using UnityEngine;
namespace Supyrb
{
[System.Serializable]
public class SerializableDateTime : IComparable<SerializableDateTime>
{
[SerializeField]
private long m_ticks;
private bool initialized;
private DateTime m_dateTime;
public DateTime DateTime
{
get
{
if (!initialized)
{
m_dateTime = new DateTime(m_ticks);
initialized = true;
}
return m_dateTime;
}
}
public SerializableDateTime(DateTime dateTime)
{
m_ticks = dateTime.Ticks;
m_dateTime = dateTime;
initialized = true;
}
public int CompareTo(SerializableDateTime other)
{
if (other == null)
{
return 1;
}
return m_ticks.CompareTo(other.m_ticks);
}
}
}