TimeAdd is processed wrong way
tolbxela opened this issue · 4 comments
TimeAdd is set to wrong time. Since TimeAddInternal is a UNIX TimeStamp it should be processed accordingly.
Here is an example how to do it: CONVERTING TO/FROM UNIX TIMESTAMP IN C#
I have made a quick and dirty fix for the Issue.
public DateTime TimeAdd => new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
.Add(TimeSpan.FromSeconds((TimeAddInternal == 0 && TimeStamp > 0) ? TimeStamp : TimeAddInternal))
.ToLocalTime();
But the Epoch should be defined somewhere as readonly static constant:
static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
I just haven't found yet the right place in your code.
Are there any reasons not to move the library toward new frameworks (net48/netstandard21)?
We could than get rid of Epoch and use FromUnixTimeSeconds:
DateTimeOffset.FromUnixTimeSeconds(unixDateTime).DateTime.ToLocalTime();
Yep, discovered this as I've been working on things over the christmas break. I'll get a fix out soon.
I've only just recently converted the project from PCL to Net Standard. At the time Net48 and Standard21 didn't exist.
I don't want to be too aggresive moving the library forward as not everyone might migrate forward at the same speed. I will include a build target to allow using those newer APIs :)
Should I create a Pull request for my TimeAdd Fix?