Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion from integer days to Portable Duration is bugged #19

Closed
cpsusie opened this issue Sep 3, 2021 · 1 comment · Fixed by #20
Closed

Conversion from integer days to Portable Duration is bugged #19

cpsusie opened this issue Sep 3, 2021 · 1 comment · Fixed by #20
Assignees

Comments

@cpsusie
Copy link
Owner

cpsusie commented Sep 3, 2021

This (demonstrative) unit test fails:

[Fact]
public void TestPortableDurationFromDaysAccuracy()  
{  
    int totalDays = -239805;   
    TimeSpan daysAsTs = TimeSpan.FromDays(totalDays);  
    PortableDuration fromTs = daysAsTs;  
    TimeSpan andBack = (TimeSpan)fromTs;  
    Assert.True(andBack == daysAsTs);  
    Int128 ticksPerSecond = 1_000_000_000;  
    //start with minute, then hour, then day  
    Int128 ticksPerDay = ticksPerSecond * 60; //per minute  
    ticksPerDay *= 60; //per hour  
    ticksPerDay *= 24; //per day  
    Assert.True(PortableDuration.TicksPerDay == ticksPerDay);  
    Int128 totalDaysInNanoSeconds = totalDays * ticksPerDay;  
    Int128 totalDaysInNanoSecondsFromDouble = (Int128)(((double)totalDays) * ((double)(long)ticksPerDay));  
    PortableDuration fromInt = PortableDuration.FromDays(totalDays);  
    Assert.True(fromInt == fromTs);  
}

Make it pass and find anything closely related.

@cpsusie cpsusie self-assigned this Sep 3, 2021
@cpsusie
Copy link
Owner Author

cpsusie commented Sep 4, 2021

NOTE: this bug was related to double conversion (FromDays) does not have an integer overload.

@cpsusie cpsusie linked a pull request Sep 4, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant