Created
February 21, 2012 03:25
-
-
Save rpgmaker/1873410 to your computer and use it in GitHub Desktop.
BytesToTimeSpan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static TimeSpan BytesToTimeSpan(byte[] buffer) { | |
if (buffer.Length == 1) { | |
if (buffer[0] == 0) return TimeSpan.MinValue; | |
else return TimeSpan.MaxValue; | |
} else if (buffer.Length == 2) { | |
return TimeSpan.FromTicks(TimeSpanTicks[buffer[0]] * buffer[1]); | |
} | |
var buffer2 = new byte[buffer.Length - 1]; | |
Buffer.BlockCopy(buffer, 1, buffer2, 0, buffer2.Length); | |
var ticks = BytesToInt64(buffer2); | |
return TimeSpan.FromTicks(buffer[0] == TimeSpanTicksLength ? ticks : ticks * TimeSpanTicks[buffer[0]]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment