Java Code Examples for org.joda.time.LocalDate.minusDays()

The following are Jave code examples for showing how to use minusDays() of the org.joda.time.LocalDate class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: yum   File: MenusService.java   Source Code and License Vote up 6 votes
private DateTime getDeadline(LocalDate date) {
    Settings settings = settingsRepo.findById(1);
    int deadlineDays = settings.getDeadlineDays();
    LocalTime deadlineTime = settings.getDeadline();
     
    date = date.minusDays(deadlineDays);
    
    while (this.holidaysRepo.findByIdHoliday(date) != null) {
         date = date.minusDays(1);
    }        
    
    // Check if order deadline passed based on given date, deadlineDays and deadlineTime (deadline)
    //return (date.toLocalDateTime(deadlineTime).compareTo(LocalDateTime.now()) < 0);

    // When we ll change deadline time to utc, use this: 
    //return date.toLocalDateTime(deadlineTime).toDateTime(DateTimeZone.UTC);
    return date.toLocalDateTime(deadlineTime).toDateTime(); // To default zone
}
 
Example 2
Project: yum   File: GlobalsettingsService.java   Source Code and License Vote up 5 votes
private boolean oldDeadlinePassed(LocalDate date, int deadlineDays, LocalTime deadlineTime) {
    // Check if order deadline passed based on given date, deadlineDays and deadlineTime (deadline)
    date = date.minusDays(deadlineDays);
    while (this.holidaysRepo.findByIdHoliday(date) != null) {
         date = date.minusDays(1);
    }  
    return (date.toLocalDateTime(deadlineTime).compareTo(LocalDateTime.now()) < 0);
}
 
Example 3
Project: yum   File: MenusService.java   Source Code and License Vote up 5 votes
@Transactional
public List<DailyMenu> menusWeeklyGet(Long userId) throws ApiException, Exception {
    LocalDate today = LocalDate.now();
    LocalDate firstDayOfWeek = today.minusDays(today.getDayOfWeek() - 1);
    List<com.jrtechnologies.yum.api.model.DailyMenu> weeklyMenu = new ArrayList<>();
    for (int i = 0; i < 7; i++) {
        DailyMenu dailymenu = createWeekDailyMenu(firstDayOfWeek.plusDays(i), userId);
        if (dailymenu.getDate() != null) {
            weeklyMenu.add(dailymenu);
        }
    }
    return weeklyMenu;
}
 
Example 4
Project: yum   File: DailyMenuService.java   Source Code and License Vote up 5 votes
public boolean deadlinePassed(LocalDate date) {
    Settings settings = settingsRepo.findOne(1);
    int deadlineDays = settings.getDeadlineDays();
    LocalTime deadlineTime = settings.getDeadline();
     
    date = date.minusDays(deadlineDays);
    
    while (this.holidaysRepo.findByIdHoliday(date) != null) {
         date = date.minusDays(1);
    }        
    
    // Check if order deadline passed based on given date, deadlineDays and deadlineTime (deadline)
    return (date.toLocalDateTime(deadlineTime).compareTo(LocalDateTime.now()) < 0);
}
 
Example 5
Project: yum   File: OrdersService.java   Source Code and License Vote up 5 votes
public boolean deadlinePassed(LocalDate date) {
    Settings settings = settingsRep.findOne(1);
    int deadlineDays = settings.getDeadlineDays();
    LocalTime deadlineTime = settings.getDeadline();

    date = date.minusDays(deadlineDays);

    while (this.holidaysRepo.findByIdHoliday(date) != null) {
        date = date.minusDays(1);
    }

    // Check if order deadline passed based on given date, deadlineDays and deadlineTime (deadline)
    return (date.toLocalDateTime(deadlineTime).compareTo(LocalDateTime.now()) < 0);
}
 
Example 6
Project: yum   File: UsersService.java   Source Code and License Vote up 5 votes
public boolean deadlinePassed(LocalDate date) {
    Settings settings = settingsRepo.findOne(1);
    int deadlineDays = settings.getDeadlineDays();
    LocalTime deadlineTime = settings.getDeadline();

    date = date.minusDays(deadlineDays);

    while (this.holidaysRepo.findByIdHoliday(date) != null) {
        date = date.minusDays(1);
    }

    // Check if order deadline passed based on given date, deadlineDays and deadlineTime (deadline)
    return (date.toLocalDateTime(deadlineTime).compareTo(LocalDateTime.now()) < 0);
}
 
Example 7
Project: yum   File: MenusService.java   Source Code and License Vote up 4 votes
@Transactional
public List<DailyMenu> menusWeeklyWeekGet(String week, Long userId) throws ApiException, Exception {
     
    
    String patternString = "^\\d{2}-\\d{4}$";
    java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(patternString);
    Matcher matcher = pattern.matcher(week);
    if (matcher.matches()) {
        int year = Integer.parseInt(week.substring(3, 7)); 
        
        int weekNumber = Integer.parseInt(week.substring(0, 2));
        int weeksOfYear = getWeeksofYear(year);
        //Validation check for weeks number.
        if (weekNumber < 1 || weekNumber > 53 || (weeksOfYear == 52 && weekNumber == 53)) {
            throw new ApiException(400, "Weekly menu not found");
        }
        LocalDate firstDayOfWeek;
        /* If year have 52 weeks but end in next week
         * (it haven't 53 weeks, then some days is in next year) then print 
         * first week of next year with last days of previous year.
         */
        if (weeksOfYear == 53 && weekNumber == 53) { 
            weekNumber = 01;
            year += 1;
        }
         
        
        firstDayOfWeek = new LocalDate().withYear(year).withWeekOfWeekyear(weekNumber);
        firstDayOfWeek = firstDayOfWeek.minusDays(firstDayOfWeek.getDayOfWeek() - 1); 
       
        List<com.jrtechnologies.yum.api.model.DailyMenu> weeklyMenu = new ArrayList<>();
        for (int i = 0; i < 7; i++) {
            DailyMenu dailymenu = createWeekDailyMenu(firstDayOfWeek.plusDays(i), userId);
            if (dailymenu.getDate() != null) {
                weeklyMenu.add(dailymenu);
            }
        }
        return weeklyMenu;
    } else {
        throw new ApiException(400, "Weekly menu not found");
    }
}