forked from uml-robotics/ROS.NET
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathTimeData.cs
45 lines (37 loc) · 1.07 KB
/
TimeData.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
using System;
namespace Uml.Robotics.Ros
{
public struct TimeData
{
public static readonly TimeData Zero = new TimeData(0, 0);
public int sec;
public int nsec;
public TimeData(int s, int ns)
{
sec = s;
nsec = ns;
}
public bool Equals(TimeData timer)
{
return (sec == timer.sec && nsec == timer.nsec);
}
public long Ticks
{
get { return sec * TimeSpan.TicksPerSecond + (long)Math.Floor(nsec / 100.0); }
}
public TimeSpan ToTimeSpan()
{
return new TimeSpan(this.Ticks);
}
public static TimeData FromTicks(long ticks)
{
long seconds = (long)Math.Floor(ticks / (double)TimeSpan.TicksPerSecond);
long nanoseconds = 100 * (ticks % TimeSpan.TicksPerSecond);
return new TimeData((int)seconds, (int)nanoseconds);
}
public static TimeData FromTimeSpan(TimeSpan value)
{
return FromTicks(value.Ticks);
}
}
}