This commit is contained in:
Nikolay Zdravkov 2026-05-02 20:00:34 +01:00 committed by GitHub
commit a73f02e4da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 12 additions and 21 deletions

View file

@ -350,9 +350,9 @@ public void FolderSetLastWriteTime(string path, DateTime dateTime)
{
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
if (dateTime.Before(DateTimeExtensions.Epoch))
if (dateTime.Before(DateTime.UnixEpoch))
{
dateTime = DateTimeExtensions.Epoch;
dateTime = DateTime.UnixEpoch;
}
Directory.SetLastWriteTimeUtc(path, dateTime);
@ -362,9 +362,9 @@ public void FileSetLastWriteTime(string path, DateTime dateTime)
{
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
if (dateTime.Before(DateTimeExtensions.Epoch))
if (dateTime.Before(DateTime.UnixEpoch))
{
dateTime = DateTimeExtensions.Epoch;
dateTime = DateTime.UnixEpoch;
}
File.SetLastWriteTime(path, dateTime);

View file

@ -63,6 +63,5 @@ public static DateTime StartOfDay(this DateTime date)
return new DateTime(date.Year, date.Month, date.Day, 0, 0, 0, 0);
}
public static DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
}
}

View file

@ -99,7 +99,7 @@ public static string GetTimestamp(DateTime dateTime)
private static long ToUnixTime(DateTime dateTime)
{
var timeSpan = dateTime - new DateTime(1970, 1, 1);
var timeSpan = dateTime - DateTime.UnixEpoch;
var timestamp = (long)timeSpan.TotalSeconds;
return timestamp;

View file

@ -95,7 +95,7 @@ public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
Grabs = torrent.Snatched,
Seeders = torrent.Seeders,
Peers = torrent.Leechers + torrent.Seeders,
PublishDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).ToUniversalTime().AddSeconds(torrent.Time),
PublishDate = DateTime.UnixEpoch.AddSeconds(torrent.Time),
Origin = torrent.Origin,
Source = torrent.Source,
Container = torrent.Container,

View file

@ -444,7 +444,7 @@ public async Task DoLogin()
var enctype = form.GetAttribute("enctype");
if (enctype == "multipart/form-data")
{
var boundary = "---------------------------" + DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds.ToString().Replace(".", "");
var boundary = "---------------------------" + (DateTime.UtcNow - DateTime.UnixEpoch).TotalSeconds.ToString().Replace(".", "");
var bodyParts = new List<string>();
foreach (var pair in pairs)

View file

@ -1138,8 +1138,6 @@ public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
foreach (var row in jsonContent.Value<JArray>("results"))
{
var dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
var id = row.Value<string>("id");
var details = _settings.BaseUrl + "collection/" + id;
@ -1157,7 +1155,7 @@ public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
DownloadUrl = _settings.BaseUrl + "download/" + id,
Title = parsedTitle.Groups["title"].Value,
Categories = row.Value<JArray>("group_ids").SelectMany(g => _categories.MapTrackerCatToNewznab(g.Value<string>())).Distinct().ToList(),
PublishDate = dateTime.AddMilliseconds(row.Value<long>("posted")).ToLocalTime(),
PublishDate = DateTime.UnixEpoch.AddMilliseconds(row.Value<long>("posted")).ToLocalTime(),
Size = row.Value<long>("size"),
Files = row.Value<int>("file_count")
};

View file

@ -226,8 +226,6 @@ public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
foreach (var row in jsonContent.Value<JArray>("rows"))
{
var dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
var id = row.Value<string>("id");
var details = _settings.BaseUrl + "details.php?id=" + id;
var seeders = row.Value<int>("seeders");
@ -243,7 +241,7 @@ public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
DownloadUrl = _settings.BaseUrl + "download.php?id=" + id + "&apikey=" + _settings.ApiKey,
Title = row.Value<string>("name"),
Categories = _categories.MapTrackerCatToNewznab(row.Value<int>("category").ToString()),
PublishDate = dateTime.AddSeconds(row.Value<long>("added")).ToLocalTime(),
PublishDate = DateTime.UnixEpoch.AddSeconds(row.Value<long>("added")).ToLocalTime(),
Size = row.Value<long>("size"),
Files = row.Value<int>("numfiles"),
Seeders = seeders,

View file

@ -160,7 +160,7 @@ public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
var seeders = torrent.Seeders ?? 0;
var leechers = torrent.Leechers ?? 0;
var grabs = torrent.Completed ?? 0;
var publishDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(torrent.Created);
var publishDate = DateTime.UnixEpoch.AddSeconds(torrent.Created);
var release = new TorrentInfo
{

View file

@ -27,17 +27,13 @@ public static DateTime UnixTimestampToDateTime(long unixTime)
public static DateTime UnixTimestampToDateTime(double unixTime)
{
var unixStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
var unixTimeStampInTicks = (long)(unixTime * TimeSpan.TicksPerSecond);
return new DateTime(unixStart.Ticks + unixTimeStampInTicks);
return new DateTime(DateTime.UnixEpoch.Ticks + unixTimeStampInTicks, DateTimeKind.Utc);
}
public static double DateTimeToUnixTimestamp(DateTime dt)
{
var date = dt.ToUniversalTime();
var ticks = date.Ticks - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).Ticks;
var ts = ticks / TimeSpan.TicksPerSecond;
return ts;
return (double)new DateTimeOffset(dt.ToUniversalTime()).ToUnixTimeSeconds();
}
// ex: "2 hours 1 day"