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

8351017: ChronoUnit.MONTHS.between() not giving correct result when date is in February #23937

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/java.base/share/classes/java/time/temporal/TemporalUnit.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -239,9 +239,15 @@ default boolean isSupportedBy(Temporal temporal) {
* calculated using {@code HOURS.between(startTime, endTime)}.
* <p>
* The calculation returns a whole number, representing the number of
* complete units between the two temporals.
* complete units between the two temporals. If there are smaller unit
* fields, their values are considered when determining the final
* whole number.
*
* For example, the amount in hours between the times 11:30 and 13:29
* will only be one hour as it is one minute short of two hours.
* will only be one hour as it is one minute short of two hours, or
* the amount in months between the dates 2024-09-29 and 2025-02-28
* (the last day in February) will be 4 months as it is one day short
* of 5 months.
* <p>
* There are two equivalent ways of using this method.
* The first is to invoke this method directly.
Expand Down