< prev index next >

src/java.base/share/classes/java/time/LocalDate.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2016, 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -1367,10 +1367,27 @@
      */
     public LocalDate plusDays(long daysToAdd) {
         if (daysToAdd == 0) {
             return this;
         }
+        long dom = day + daysToAdd;
+        if (dom > 0) {
+            if (dom <= 28) {
+                return new LocalDate(year, month, (int) dom);
+            } else if (dom <= 59) { // 59th Jan is 28th Feb, 59th Feb is 31st Mar
+                long monthLen = lengthOfMonth();
+                if (dom <= monthLen) {
+                    return new LocalDate(year, month, (int) dom);
+                } else if (month < 12) {
+                    return new LocalDate(year, month + 1, (int) (dom - monthLen));
+                } else {
+                    YEAR.checkValidValue(year + 1);
+                    return new LocalDate(year + 1, 1, (int) (dom - monthLen));
+                }
+            }
+        }
+
         long mjDay = Math.addExact(toEpochDay(), daysToAdd);
         return LocalDate.ofEpochDay(mjDay);
     }
 
     //-----------------------------------------------------------------------
< prev index next >