projectgoav / E.Deezer

Unoffical asynchronous Deezer .NET API
16 stars 11 forks source link

TimeAdd is processed wrong way #86

Open tolbxela opened 4 years ago

tolbxela commented 4 years ago

image

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#

tolbxela commented 4 years ago

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.

tolbxela commented 4 years ago

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();

projectgoav commented 4 years ago

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 :)

tolbxela commented 4 years ago

Should I create a Pull request for my TimeAdd Fix?