[gnome-shell] calendar: Fix prev/next buttons to not skip months



commit 8fea88879a42d248edbb107449aee7efad7fda15
Author: Adel Gadllah <adel gadllah gmail com>
Date:   Mon Jan 31 21:00:16 2011 +0100

    calendar: Fix prev/next buttons to not skip months
    
    When the current day does not exist in the next/prev month (like 31 Feb),
    the next/prev buttons end up skipping the month.
    
    Fix that by going to the last day of the month instead.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=641067

 js/ui/calendar.js |   36 +++++++++++++++++++++++++++++-------
 1 files changed, 29 insertions(+), 7 deletions(-)
---
diff --git a/js/ui/calendar.js b/js/ui/calendar.js
index 236c3ec..07b9d29 100644
--- a/js/ui/calendar.js
+++ b/js/ui/calendar.js
@@ -488,23 +488,45 @@ Calendar.prototype = {
 
     _onPrevMonthButtonClicked: function() {
         let newDate = new Date(this._selectedDate);
-        if (newDate.getMonth() == 0) {
+        let oldMonth = newDate.getMonth();
+        if (oldMonth == 0) {
             newDate.setMonth(11);
             newDate.setFullYear(newDate.getFullYear() - 1);
-        } else {
-            newDate.setMonth(newDate.getMonth() - 1);
+            if (newDate.getMonth() != 11) {
+                let day = 32 - new Date(newDate.getFullYear() - 1, 11, 32).getDate();
+                newDate = new Date(newDate.getFullYear() - 1, 11, day);
+            }
         }
+        else {
+            newDate.setMonth(oldMonth - 1);
+            if (newDate.getMonth() != oldMonth - 1) {
+                let day = 32 - new Date(newDate.getFullYear(), oldMonth - 1, 32).getDate();
+                newDate = new Date(newDate.getFullYear(), oldMonth - 1, day);
+            }
+        }
+
         this.setDate(newDate);
    },
 
-    _onNextMonthButtonClicked: function() {
+   _onNextMonthButtonClicked: function() {
         let newDate = new Date(this._selectedDate);
-        if (newDate.getMonth() == 11) {
+        let oldMonth = newDate.getMonth();
+        if (oldMonth == 11) {
             newDate.setMonth(0);
             newDate.setFullYear(newDate.getFullYear() + 1);
-        } else {
-            newDate.setMonth(newDate.getMonth() + 1);
+            if (newDate.getMonth() != 0) {
+                let day = 32 - new Date(newDate.getFullYear() + 1, 0, 32).getDate();
+                newDate = new Date(newDate.getFullYear() + 1, 0, day);
+            }
         }
+        else {
+            newDate.setMonth(oldMonth + 1);
+            if (newDate.getMonth() != oldMonth + 1) {
+                let day = 32 - new Date(newDate.getFullYear(), oldMonth + 1, 32).getDate();
+                newDate = new Date(newDate.getFullYear(), oldMonth + 1, day);
+            }
+        }
+
         this.setDate(newDate);
     },
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]