mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-05 23:06:10 +00:00
* The equivalent of `public static DateTimeOffset FromUnixTime(this long unixTime)` exists in the framework since .NET Framework 4.6: https://docs.microsoft.com/en-us/dotnet/api/system.datetimeoffset.fromunixtimeseconds * The equivalent of `public static long ToUnixTime(this DateTimeOffset date)` exists in the framework since .NET Framework 4.6: https://docs.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tounixtimeseconds
31 lines
1.0 KiB
C#
31 lines
1.0 KiB
C#
using System;
|
|
|
|
namespace Octokit.Helpers
|
|
{
|
|
/// <summary>
|
|
/// Extensions for converting between different time representations
|
|
/// </summary>
|
|
public static class UnixTimestampExtensions
|
|
{
|
|
/// <summary>
|
|
/// Convert a Unix tick to a <see cref="DateTimeOffset"/> with UTC offset
|
|
/// </summary>
|
|
/// <param name="unixTime">UTC tick</param>
|
|
[Obsolete("Use DateTimeOffset.FromUnixTimeSeconds(long seconds) instead.")]
|
|
public static DateTimeOffset FromUnixTime(this long unixTime)
|
|
{
|
|
return DateTimeOffset.FromUnixTimeSeconds(unixTime);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Convert <see cref="DateTimeOffset"/> with UTC offset to a Unix tick
|
|
/// </summary>
|
|
/// <param name="date">Date Time with UTC offset</param>
|
|
[Obsolete("Use DateTimeOffset.ToUnixTimeSeconds() instead.")]
|
|
public static long ToUnixTime(this DateTimeOffset date)
|
|
{
|
|
return date.ToUnixTimeSeconds();
|
|
}
|
|
}
|
|
}
|