Skip to content

Period.Between can report partially-negative values #824

Closed

Description

@jskeet

This isn't meant to happen...

Reported on http://stackoverflow.com/questions/44087757

var start = DateTime.Now;
var end = start.AddDays(7).AddMinutes(-1);
        
var period = Period.Between(LocalDateTime.FromDateTime(start), LocalDateTime.FromDateTime(end));
Console.WriteLine(period); // P6DT24H-1M

More investigation required.

Activity

  1. self-assigned this
    on May 20, 2017
  2. jskeet commented on May 20, 2017

    @jskeet
    MemberAuthor

    Version without DateTime:

    var start = new LocalDateTime(2017, 5, 20, 18, 49, 30)
        .PlusTicks(4498940);
    var end = start.PlusDays(7).PlusMinutes(-1);
    var period = Period.Between(start, end);
    Console.WriteLine(period);
  3. jskeet commented on May 20, 2017

    @jskeet
    MemberAuthor

    Even a simple example is broken in 2.0:

    var start = new LocalDateTime(2017, 5, 20, 18, 49, 30);
    var end = start.PlusDays(1).PlusMinutes(-30);
            
    var period = Period.Between(start, end);
    Console.WriteLine(period);

    ... but it works in 1.3. I think this is broken for every period which should have "23 hours and a bit".

  4. jskeet commented on May 20, 2017

    @jskeet
    MemberAuthor

    It's worse than that - I think it's broken for all periods where the end time is later than the start time :( Definitely an urgent fix, and will require a 2.0.2 as soon as it is fixed. (The good news is it's quite a localized bug, but I need sleep before I can fix it, I think.)

  5. added a commit that references this issue on May 21, 2017
    917c6f6
  6. added 3 commits that reference this issue on May 22, 2017
    237b9f7
    3b22fe8
    aecdeea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions