Skip to content

End-of-month arithmetic can cause mixed-polarity periods #223

Closed

Description

@GoogleCodeExporter
We claim that Period.Between(x, y) will always return a period of either 
all-non-negative values, or all-non-positive values. Unfortunately this doesn't 
quite work:

    LocalDate d1 = new LocalDate(2013, 3, 31);
    LocalDate d2 = new LocalDate(2013, 4, 30);
    Period period = Period.Between(d2, d1);

The result is P-1M1D, as subtraction is always really performed from a later 
value to an earlier one... the first part is determined to be -1 month, but 
then adding -1 month to April 30th gives March 30th, so an extra day is added.

When we find the number of months, we should disallow the end-of-month rounding 
if we were originally going "backwards".

Original issue reported on code.google.com by jonathan.skeet on 11 Jun 2013 at 3:30

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions