Created
April 1, 2015 17:03
-
-
Save brentmaxwell/60c3b3896212304aab15 to your computer and use it in GitHub Desktop.
Extensions for GPS time
This file contains 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
namespace System | |
{ | |
public static class GpsTime | |
{ | |
public static int ToGpsTimeWeekNumber(this DateTime datetime) | |
{ | |
DateTime datum = new DateTime(1980, 1, 6, 0, 0, 0); | |
TimeSpan difference = datetime.Subtract(datum); | |
return (int)(difference.TotalDays / 7); | |
} | |
public static int ToGpsTimeSeconds(this DateTime datetime) | |
{ | |
DateTime datum = new DateTime(1980, 1, 6, 0, 0, 0); | |
DateTime secondsdiff = datetime.AddDays(datetime.ToGpsTimeWeekNumber() * -7); | |
TimeSpan difference = secondsdiff.Subtract(datum); | |
return (int)difference.TotalSeconds; | |
} | |
public static DateTime FromGpsTime(int weeknumber, int seconds) | |
{ | |
return new DateTime(1980, 1, 6, 0, 0, 0).AddDays(weeknumber * 7).AddSeconds(seconds); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment