Home Forums CalendarFX Week numbers in YearMonthView

  • Author
    Posts
  • NHS
    Participant
    Post count: 26
    #13095 |

    Is there bug in week numbers?. Is shows up to week 57 in January 2016?

  • Dirk Lemmermann
    Keymaster
    Post count: 60
    #13099 |

    Yes, this is a bug. Will be fixed in the next release. Currently I am planning to finish the next release first week in January.

  • NHS
    Participant
    Post count: 26
    #13102 |

    OK sounds good with first week.

  • Dirk Lemmermann
    Keymaster
    Post count: 60
    #13110 |

    Sorry to inform you that I will not be able to ship the next release (which will carry the version number 2.0.0) this week. I have to delay it by one week.

  • Dirk Lemmermann
    Keymaster
    Post count: 60
    #13139 |

    OK, so finally I shipped the new release. It is version 8.4.0. Please read the CHANGES.txt file and be aware that the changes are quite big, especially in the area of scene graph structure and CSS styling. Upgrading to this release will mean work on your end as well.

    • NHS
      Participant
      Post count: 26
      #13141 |

      Thanks

  • NHS
    Participant
    Post count: 26
    #13179 |

    Hi,

    Can you share the actual code fix for this problem?

    • Dirk Lemmermann
      Keymaster
      Post count: 60
      #13180 |

      The key is to find the first day of the week and then determine the week number for that day.

      
      LocalDate date = ... coming from somewhere
      
      // WeekFields are used to determine min number of days in first week of the year 
      // and the first day of the week ("sunday" in the US or "monday" in Germany)
      WeekFields weekFields = WeekFields.of(Locale.getDefault());  
      date = Util.adjustToFirstDayOfWeek(date, weekFields.getFirstDayOfWeek());
      
      // The YearMonthView control always shows six weeks
      for (int i = 0; i < 6; i++) {
         int weekOfYear = date.get(weekFields.weekOfYear());
         System.out.println(weekOfYear);
         date = date.plusWeeks(1); // go to the next week
      }
      

      The code above delegates to a utility method that is available to you, too.

      
      /**
       * Adjusts the given date to a new date that marks the beginning of the week where the
       * given date is located. If "Monday" is the first day of the week and the given date
       * is a "Wednesday" then this method will return a date that is two days earlier than the
       * given date.
       *
       * @param date the date to adjust
       * @param firstDayOfWeek the day of week that is considered the start of the week ("Monday" in Germany, "Sunday" in the US)
       * @return the date of the first day of the week
       * @see #adjustToLastDayOfWeek(LocalDate, DayOfWeek)
       * @see DateControl#getFirstDayOfWeek()
       */
      public static LocalDate adjustToFirstDayOfWeek(LocalDate date, DayOfWeek firstDayOfWeek) {
         LocalDate newDate = date.with(DAY_OF_WEEK, firstDayOfWeek.getValue());
         if (newDate.isAfter(date)) {
            newDate = newDate.minusWeeks(1);
         }
         return newDate;
      }
      
      • This reply was modified 2 months, 3 weeks ago by  Dirk Lemmermann. Reason: Updated code example
      • This reply was modified 2 months, 3 weeks ago by  Dirk Lemmermann. Reason: Updated code formatting
      • This reply was modified 2 months, 3 weeks ago by  Dirk Lemmermann. Reason: More code cleanup
  • NHS
    Participant
    Post count: 26
    #13184 |

    Nice!

You must be logged in to reply to this topic.