Strange behavior with february when calculate period and espessially the month calculation #31

aky0 opened this Issue Jun 11, 2013 · 1 comment

2 participants


about the february month there is a strange behavior that you can see in the incorect results with jodatime, you can look down here :

        DateTime date4 = new DateTime(2013, 5, 29, 0, 0, 0, 0);
        DateTime date4PlusNineMonths = new DateTime(2014, 2, 28, 0, 0, 0, 0);
        Period period4 = new Period(date4, date4PlusNineMonths);
        //Incorrect result
        System.out.print(date4.toString("dd/MM/YYYY")+".plusMonths(9) = "+ date4.plusMonths(9).toString("dd/MM/YYYY"));
        System.out.print(period4.getYears() +"Years/"+ period4.getMonths() +"Months/"+ period4.getWeeks() +"Weeks/"+ period4.getDays() +"Days");

Output :
29/05/2013.plusMonths(9) = 28/02/2014 //incorrect result should be 01/03/2014

This is an incorrect calculation It should be 0Years/8Months/4Weeks/2Days Isn't it...?

If it is correct so why when I increase two days more (30 and 31) it always give me the same calculation (0Years/9Months/0Weeks/0Days) we all agree that days are really decreasing or am I dreaming...?

Now maybe I wrong in my use of the joda framework because in the app I develop I do a check everyday on a period to have the precise month separation between two date (toDay and the next date) and if I have 9months and 1day it's too late I need to have 9months and 0days as required in my app =/

If I wrong how can I achieve this please...?

@jodastephen jodastephen was assigned Jun 16, 2013
@jodastephen member

This is the correct result, I've updated the Javadoc. It may not be the obvious result, but it does work in that

There is no functionality to match what you want. However the Period.fieldDifference() method may help you.

@Guardiola31337 Guardiola31337 pushed a commit to Guardiola31337/joda-time that referenced this issue Sep 25, 2015
@jodastephen jodastephen Investigate Period calculation at end of month
See #31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment