List of usage examples for org.joda.time DateTime getDayOfWeek
public int getDayOfWeek()
From source file:ru.touchin.templates.calendar.CalendarUtils.java
License:Apache License
/** * Create list of {@link CalendarItem} according to start and end Dates. * * @param startDate Start date of the range; * @param endDate End date of the range; * @return List of CalendarItems that could be one of these: {@link CalendarHeaderItem}, {@link CalendarDayItem} or {@link CalendarEmptyItem}. *//*from ww w . j av a 2 s .com*/ @NonNull @SuppressWarnings("checkstyle:MethodLength") public static List<CalendarItem> fillRanges(@NonNull final DateTime startDate, @NonNull final DateTime endDate) { final DateTime cleanStartDate = startDate.withTimeAtStartOfDay(); final DateTime cleanEndDate = endDate.plusDays(1).withTimeAtStartOfDay(); DateTime tempTime = cleanStartDate; final List<CalendarItem> calendarItems = fillCalendarTillCurrentDate(cleanStartDate, tempTime); tempTime = tempTime.plusDays(Days.ONE.getDays()); final int totalDaysCount = Days.daysBetween(tempTime, cleanEndDate).getDays(); int shift = calendarItems.get(calendarItems.size() - 1).getEndRange(); int firstDate = tempTime.getDayOfMonth() - 1; int daysEnded = 1; while (true) { final int daysInCurrentMonth = tempTime.dayOfMonth().getMaximumValue(); final long firstRangeDate = tempTime.getMillis(); if ((daysEnded + (daysInCurrentMonth - firstDate)) <= totalDaysCount) { tempTime = tempTime.plusMonths(1).withDayOfMonth(1); calendarItems.add(new CalendarDayItem(firstRangeDate, firstDate + 1, shift + daysEnded, shift + daysEnded + (daysInCurrentMonth - firstDate) - 1, ComparingToToday.AFTER_TODAY)); daysEnded += daysInCurrentMonth - firstDate; if (daysEnded == totalDaysCount) { break; } firstDate = 0; final int firstDayInWeek = tempTime.getDayOfWeek() - 1; if (firstDayInWeek != 0) { calendarItems.add(new CalendarEmptyItem(shift + daysEnded, shift + daysEnded + (DAYS_IN_WEEK - firstDayInWeek - 1))); shift += (DAYS_IN_WEEK - firstDayInWeek); } calendarItems.add(new CalendarHeaderItem(tempTime.getYear(), tempTime.getMonthOfYear() - 1, shift + daysEnded, shift + daysEnded)); shift += 1; if (firstDayInWeek != 0) { calendarItems .add(new CalendarEmptyItem(shift + daysEnded, shift + daysEnded + firstDayInWeek - 1)); shift += firstDayInWeek; } } else { calendarItems.add(new CalendarDayItem(firstRangeDate, firstDate + 1, shift + daysEnded, shift + totalDaysCount, ComparingToToday.AFTER_TODAY)); break; } } return calendarItems; }
From source file:ru.touchin.templates.calendar.CalendarUtils.java
License:Apache License
@NonNull private static List<CalendarItem> fillCalendarTillCurrentDate(@NonNull final DateTime cleanStartDate, @NonNull final DateTime startDate) { DateTime temp = startDate; final List<CalendarItem> calendarItems = new ArrayList<>(); int shift = 0; final int firstDate = temp.getDayOfMonth() - 1; //?? - 1 ? // add first month header calendarItems.add(new CalendarHeaderItem(temp.getYear(), temp.get(DateTimeFieldType.monthOfYear()) - 1, shift, shift)); // is Month starts from 1 or 0 ? temp = temp.withDayOfMonth(1);// ww w .j a v a 2 s .c o m shift += 1; final int firstDayInTheWeek = temp.getDayOfWeek() - 1; // check if first day is Monday. If not - add empty items. Otherwise do nothing if (firstDayInTheWeek != 0) { calendarItems.add(new CalendarEmptyItem(shift, shift + firstDayInTheWeek - 1)); } shift += firstDayInTheWeek; // add range with days before today calendarItems.add(new CalendarDayItem(temp.getMillis(), 1, shift, shift + firstDate - 1, ComparingToToday.BEFORE_TODAY)); shift += firstDate; // add today item temp = cleanStartDate; calendarItems .add(new CalendarDayItem(temp.getMillis(), firstDate + 1, shift, shift, ComparingToToday.TODAY)); //add empty items and header if current day the last day in the month if (temp.getDayOfMonth() == temp.dayOfMonth().getMaximumValue()) { addItemsIfCurrentDayTheLastDayInTheMonth(startDate, calendarItems); } return calendarItems; }
From source file:ru.touchin.templates.calendar.CalendarUtils.java
License:Apache License
private static void addItemsIfCurrentDayTheLastDayInTheMonth(@NonNull final DateTime dateTime, @NonNull final List<CalendarItem> calendarItems) { int shift = calendarItems.get(calendarItems.size() - 1).getEndRange(); final DateTime nextMonthFirstDay = dateTime.plusDays(1); final int firstDayInNextMonth = nextMonthFirstDay.getDayOfWeek() - 1; calendarItems.add(new CalendarEmptyItem(shift + 1, shift + (7 - firstDayInNextMonth))); shift += 7 - firstDayInNextMonth + 1; calendarItems.add(new CalendarHeaderItem(nextMonthFirstDay.getYear(), nextMonthFirstDay.getMonthOfYear() - 1, shift, shift)); shift += 1;/*w w w . j a va2 s . c o m*/ calendarItems.add(new CalendarEmptyItem(shift, shift + firstDayInNextMonth - 1)); }
From source file:sk.linhard.openair.android.OpenAirApplication.java
License:Open Source License
public String getDayString(DateTime time) { String dayString = getString(DAY_OF_WEEK[time.getDayOfWeek()]); return dayString + " " + DAY_FORMAT.print(time); }
From source file:view.Configuration.java
/** * Read the preferences from disk and fill the text fields with the * appropriate data./*w w w . j a va2s .co m*/ */ private void loadPreferences() { connectToJira.setSelected(preferences.connectToJiraAtStartup()); urlTextField.setText(preferences.getJiraUrl()); passwordPasswordField.setText(preferences.getPassword()); usernaneTextField.setText(preferences.getUserName()); DateTime alarmTime = preferences.getBeerTime(); alarmDay.setSelectedIndex(alarmTime.getDayOfWeek() - 1); alarmHour.setSelectedItem(String.valueOf(alarmTime.getHourOfDay())); alarmMinute.setSelectedItem(String.valueOf(alarmTime.getMinuteOfHour())); killOnAlarm.setSelected(preferences.getKillOnBeer()); }
From source file:windows.Recursos.java
/** * Este metodo se encarga de buscar todas las semnas en el ao actual * * @return numero de semanas/* www .j av a 2s.c om*/ */ public static int generateWeeks() { // SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy"); DateTime d = new DateTime(); Period weekPeriod = new Period().withWeeks(1); DateTime startDate = new DateTime(d.getYear(), 1, 1, 0, 0, 0, 0); while (startDate.getDayOfWeek() != DateTimeConstants.MONDAY) { startDate = startDate.plusDays(1); } DateTime endDate = new DateTime(d.getYear() + 1, 1, 1, 0, 0, 0, 0); Interval i = new Interval(startDate, weekPeriod); int ct = 0; while (i.getStart().isBefore(endDate)) { i = new Interval(i.getStart().plus(weekPeriod), weekPeriod); ct++; } return ct; }
From source file:windows.Recursos.java
public static int getActualweek() { // SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy"); DateTime d = new DateTime(); Period weekPeriod = new Period().withWeeks(1); DateTime startDate = new DateTime(d.getYear(), 1, 1, 0, 0, 0, 0); while (startDate.getDayOfWeek() != DateTimeConstants.MONDAY) { startDate = startDate.plusDays(1); }//from w w w .j a v a 2 s . c om DateTime endDate = new DateTime(d); Interval i = new Interval(startDate, weekPeriod); int ct = 0; while (i.getStart().isBefore(endDate)) { i = new Interval(i.getStart().plus(weekPeriod), weekPeriod); ct++; } return ct; }