List of usage examples for java.util Calendar setFirstDayOfWeek
public void setFirstDayOfWeek(int value)
SUNDAY
in the U.S., MONDAY
in France. From source file:Main.java
public static long getPeriodStart(int periodType, long date) { final Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(date);/*from w ww. j ava 2s . c o m*/ switch (periodType) { case TYPE_DAY: { cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); break; } case TYPE_WEEK: { cal.setFirstDayOfWeek(Calendar.MONDAY); final int currentDayOfWeek = (cal.get(Calendar.DAY_OF_WEEK) + 7 - cal.getFirstDayOfWeek()) % 7; cal.add(Calendar.DAY_OF_YEAR, -currentDayOfWeek); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); break; } case TYPE_MONTH: { cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); break; } case TYPE_YEAR: { cal.set(Calendar.MONTH, 0); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); break; } } return cal.getTimeInMillis(); }
From source file:io.lavagna.service.SearchFilter.java
private static void fromDateIdentifier(String identifier, List<Object> params) { Date todayTruncated = truncate(new Date(), Calendar.DAY_OF_MONTH); Date beginMonth = truncate(new Date(), Calendar.MONTH); // TODO: internazionalization... Calendar c = truncate(Calendar.getInstance(), Calendar.DAY_OF_MONTH); c.setFirstDayOfWeek(Calendar.MONDAY); c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); Date beginOfWeek = c.getTime(); ///*from www .j a v a 2s. co m*/ switch (identifier) { case "late": params.add(new Date(0)); params.add(todayTruncated); break; case "today": params.add(todayTruncated); params.add(addDays(todayTruncated, 1)); break; case "yesterday": params.add(addDays(todayTruncated, -1)); params.add(todayTruncated); break; case "tomorrow": params.add(addDays(todayTruncated, 1)); params.add(addDays(todayTruncated, 2)); break; case "this week": params.add(beginOfWeek); params.add(addWeeks(beginOfWeek, 1)); break; case "this month": params.add(beginMonth); params.add(addMonths(beginMonth, 1)); break; case "next week": params.add(addWeeks(beginOfWeek, 1)); params.add(addWeeks(beginOfWeek, 2)); break; case "next month": params.add(addMonths(beginMonth, 1)); params.add(addMonths(beginMonth, 2)); break; case "previous week": params.add(addWeeks(beginOfWeek, -1)); params.add(beginOfWeek); break; case "previous month": params.add(addMonths(beginMonth, -1)); params.add(beginMonth); break; case "last week": params.add(addDays(todayTruncated, -6)); params.add(addDays(todayTruncated, 1)); break; case "last month": params.add(addDays(todayTruncated, -29)); params.add(addDays(todayTruncated, 1)); break; default: break; } }
From source file:com.baifendian.swordfish.execserver.parameter.placeholder.TimePlaceholderUtil.java
/** * ? <p>/*from w w w.j a v a 2 s . c om*/ */ public static Date getSunday(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); // ? cal.setFirstDayOfWeek(Calendar.MONDAY); cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); return cal.getTime(); }
From source file:com.baifendian.swordfish.execserver.parameter.placeholder.TimePlaceholderUtil.java
/** * ? <p>/* w w w . j a v a2 s . c o m*/ */ public static Date getMonday(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); // ? cal.setFirstDayOfWeek(Calendar.MONDAY); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); return cal.getTime(); }
From source file:controllers.core.TimesheetController.java
/** * Get the timesheet report of an actor for a given string date. * //from www . ja v a2 s. co m * if the string date is empty: the start date corresponds to the first day * (monday) of the current week<br/> * else: the start date corresponds to the first day (monday) of the week * including the given date * * Note: if the report doesn't exist, the system creates it. * * @param stringDate * a date in the format yyyy-MM-dd: the system gets the weekly * report including this date, if empty it uses the current date. * @param actor * the actor of the timesheet */ public static TimesheetReport getTimesheetReport(String stringDate, Actor actor) { // get the date: either given as a parameter or the current Date date = null; if (!stringDate.equals("")) { try { DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); date = formatter.parse(stringDate); } catch (ParseException e) { log.error(e.getMessage()); return null; } } else { date = new Date(); } // get the first day of the week including the date // we consider the first day as Monday Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, 0); cal.clear(Calendar.MINUTE); cal.clear(Calendar.SECOND); cal.clear(Calendar.MILLISECOND); cal.setFirstDayOfWeek(Calendar.MONDAY); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); Date startDate = cal.getTime(); TimesheetReport report = TimesheetDao.getTimesheetReportByActorAndStartDate(actor.id, startDate); if (report == null) { report = new TimesheetReport(); report.actor = actor; report.orgUnit = actor.orgUnit; report.type = TimesheetReport.Type.WEEKLY; report.startDate = startDate; report.status = TimesheetReport.Status.OPEN; report.save(); } return report; }
From source file:com.binary_machinery.avalonschedule.view.schedule.SchedulePagerAdapter.java
private Calendar getWeekBeginning(int position) { Calendar calendar = Calendar.getInstance(); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(m_minDate);//from w ww .j a v a 2s. c o m calendar.add(Calendar.WEEK_OF_MONTH, position); calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar; }
From source file:com.binary_machinery.avalonschedule.view.schedule.SchedulePagerAdapter.java
private Calendar getWeekEnd(int position) { Calendar calendar = Calendar.getInstance(); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(m_minDate);//from w ww. ja v a 2s .c o m calendar.add(Calendar.WEEK_OF_MONTH, position); calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); calendar.set(Calendar.HOUR, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); calendar.set(Calendar.MILLISECOND, 999); return calendar; }
From source file:com.frey.repo.DateUtil.java
/** * ??//from w ww.j a v a2 s . c o m */ public static Date getMondayOfWeek(Date date) { Calendar monday = Calendar.getInstance(); monday.setTime(date); monday.setFirstDayOfWeek(FIRST_DAY_OF_WEEK); monday.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); return monday.getTime(); }
From source file:com.frey.repo.DateUtil.java
/** * ??// w w w .ja v a 2 s .c o m */ public static Date getSundayOfWeek(Date date) { Calendar sunday = Calendar.getInstance(); sunday.setTime(date); sunday.setFirstDayOfWeek(FIRST_DAY_OF_WEEK); sunday.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); return sunday.getTime(); }
From source file:br.com.transport.report.ManagerReportBean.java
/** * Retorna o ultimo dia da semana/* ww w. j a v a 2s . c o m*/ * @return */ private Calendar getLastCalendar() { Calendar end = GregorianCalendar.getInstance(); end.setFirstDayOfWeek(Calendar.SUNDAY); end.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); end.set(Calendar.HOUR_OF_DAY, 23); end.set(Calendar.MINUTE, 59); end.set(Calendar.SECOND, 59); end.setTime(end.getTime()); return end; }