List of usage examples for java.util Calendar MONDAY
int MONDAY
To view the source code for java.util Calendar MONDAY.
Click Source Link
From source file:net.chaosserver.timelord.data.ExcelDataReaderWriter.java
/** * Converts a given date to the date that marks the start of a week. * This is 12:00am on Monday.// ww w. j a va 2 s . c o m * * @param inputDate the date to find the start of week for * @return 12:00am on Monday the week of the input */ protected Date convertToWeekStart(Date inputDate) { Calendar weekStartCalendar = Calendar.getInstance(); weekStartCalendar.setTime(inputDate); weekStartCalendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); weekStartCalendar.set(Calendar.HOUR_OF_DAY, 0); weekStartCalendar.set(Calendar.MINUTE, 0); weekStartCalendar.set(Calendar.SECOND, 0); weekStartCalendar.set(Calendar.MILLISECOND, 0); // Since the day of week has changed from Monday it no // longer matches Java's natural interpretation. So if // the date is a Monday, than it's important to roll back // the week start by a week Calendar inputCalendar = Calendar.getInstance(); inputCalendar.setTime(inputDate); if (inputCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { weekStartCalendar.add(Calendar.WEEK_OF_YEAR, -1); } return weekStartCalendar.getTime(); }
From source file:org.unitime.timetable.action.PersonalizedExamReportAction.java
public int getDaysCode(Set meetings) { int daysCode = 0; for (Iterator i = meetings.iterator(); i.hasNext();) { Meeting meeting = (Meeting) i.next(); Calendar date = Calendar.getInstance(Locale.US); date.setTime(meeting.getMeetingDate()); switch (date.get(Calendar.DAY_OF_WEEK)) { case Calendar.MONDAY: daysCode |= Constants.DAY_CODES[Constants.DAY_MON]; break; case Calendar.TUESDAY: daysCode |= Constants.DAY_CODES[Constants.DAY_TUE]; break; case Calendar.WEDNESDAY: daysCode |= Constants.DAY_CODES[Constants.DAY_WED]; break; case Calendar.THURSDAY: daysCode |= Constants.DAY_CODES[Constants.DAY_THU]; break; case Calendar.FRIDAY: daysCode |= Constants.DAY_CODES[Constants.DAY_FRI]; break; case Calendar.SATURDAY: daysCode |= Constants.DAY_CODES[Constants.DAY_SAT]; break; case Calendar.SUNDAY: daysCode |= Constants.DAY_CODES[Constants.DAY_SUN]; break; }//from w w w . j a va 2s. c o m } return daysCode; }
From source file:org.everit.jira.timetracker.plugin.JiraTimetrackerWebAction.java
/** * Make summary today, this week and this month. * * @throws GenericEntityException// w ww . j av a 2 s. c om * GenericEntityException. */ public void makeSummary() throws GenericEntityException { ApplicationProperties applicationProperties = ComponentAccessor.getApplicationProperties(); boolean useISO8601 = applicationProperties.getOption(APKeys.JIRA_DATE_TIME_PICKER_USE_ISO8601); Calendar startCalendar = Calendar.getInstance(); if (useISO8601) { startCalendar.setFirstDayOfWeek(Calendar.MONDAY); } startCalendar.setTime(date); startCalendar.set(Calendar.HOUR_OF_DAY, 0); startCalendar.set(Calendar.MINUTE, 0); startCalendar.set(Calendar.SECOND, 0); startCalendar.set(Calendar.MILLISECOND, 0); Calendar originalStartcalendar = (Calendar) startCalendar.clone(); Date start = startCalendar.getTime(); Calendar endCalendar = (Calendar) startCalendar.clone(); endCalendar.add(Calendar.DAY_OF_MONTH, 1); Date end = endCalendar.getTime(); daySummary = jiraTimetrackerPlugin.summary(selectedUser, start, end, null); if ((issuesRegex != null) && !issuesRegex.isEmpty()) { dayFilteredSummary = jiraTimetrackerPlugin.summary(selectedUser, start, end, issuesRegex); } startCalendar = (Calendar) originalStartcalendar.clone(); while (startCalendar.get(Calendar.DAY_OF_WEEK) != startCalendar.getFirstDayOfWeek()) { startCalendar.add(Calendar.DATE, -1); // Substract 1 day until first day of week. } start = startCalendar.getTime(); endCalendar = (Calendar) startCalendar.clone(); endCalendar.add(Calendar.DATE, DateTimeConverterUtil.DAYS_PER_WEEK); end = endCalendar.getTime(); weekSummary = jiraTimetrackerPlugin.summary(selectedUser, start, end, null); if ((issuesRegex != null) && !issuesRegex.isEmpty()) { weekFilteredSummary = jiraTimetrackerPlugin.summary(selectedUser, start, end, issuesRegex); } startCalendar = (Calendar) originalStartcalendar.clone(); startCalendar.set(Calendar.DAY_OF_MONTH, 1); start = startCalendar.getTime(); endCalendar = (Calendar) originalStartcalendar.clone(); endCalendar.set(Calendar.DAY_OF_MONTH, endCalendar.getActualMaximum(Calendar.DAY_OF_MONTH)); endCalendar.add(Calendar.DAY_OF_MONTH, 1); end = endCalendar.getTime(); monthSummary = jiraTimetrackerPlugin.summary(selectedUser, start, end, null); if ((issuesRegex != null) && !issuesRegex.isEmpty()) { monthFilteredSummary = jiraTimetrackerPlugin.summary(selectedUser, start, end, issuesRegex); } }
From source file:com.frey.repo.DateUtil.java
/** * ??//from w ww. j a v a 2 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.panet.imeta.core.row.ValueDataUtil.java
public static Object weekOfYearISO8601(ValueMetaInterface metaA, Object dataA) throws KettleValueException { if (dataA == null) return null; if (metaA.isDate()) { Calendar calendar = Calendar.getInstance(Locale.ENGLISH); calendar.setMinimalDaysInFirstWeek(4); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(metaA.getDate(dataA)); return new Long(calendar.get(Calendar.WEEK_OF_YEAR)); }//from ww w .j ava2 s . c om throw new KettleValueException("The 'weekOfYearISO8601' function only works with dates"); }
From source file:com.baidu.rigel.biplatform.tesseract.meta.impl.TimeDimensionMemberServiceImpl.java
/** * ?// w w w . ja va 2 s. co m * * @param level * @param parentMember * @return */ private List<MiniCubeMember> genMembersFromOtherToWeek(Level level, Member parentMember) { List<MiniCubeMember> members = Lists.newArrayList(); String parentName = parentMember.getName(); String year = parentName.substring(0, 4); String month = parentName.substring(4, 6); int quarterIndex = Integer.valueOf(month) - 1; // Calendar cal = Calendar.getInstance(); Date now = cal.getTime(); // ? Date nowWeek = this.getFirstDayOfWeek(now); // ? cal.set(Calendar.YEAR, Integer.valueOf(year)); cal.set(Calendar.MONTH, Integer.valueOf(month) - 1); cal.set(Calendar.DATE, 1); cal.setFirstDayOfWeek(Calendar.MONDAY); SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd"); int count = 1; // Date firstDay = cal.getTime(); Date firstWeek = this.getFirstDayOfWeek(firstDay); // ? Date lastDay; Date lastWeek; int daysOfMonth; switch (parentMember.getLevel().getType()) { case TIME_YEARS: break; case TIME_QUARTERS: cal.add(Calendar.MONTH, 2); // ?? daysOfMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH); // ? cal.add(Calendar.DATE, daysOfMonth); lastDay = cal.getTime(); // lastWeek = this.getFirstDayOfWeek(lastDay); // // ??? if (nowWeek.before(lastWeek) || (nowWeek.compareTo(lastWeek) == 0)) { lastWeek = nowWeek; } cal.setTime(firstWeek); // ? while (cal.getTime().before(lastWeek) || (cal.getTime().compareTo(lastWeek) == 0)) { String day = sf.format(cal.getTime()); String caption = "" + (quarterIndex + 1) + "" + count + ""; caption = caption + day; MiniCubeMember dayMember = new MiniCubeMember(day); dayMember.setCaption(caption); dayMember.setLevel(level); dayMember.setParent(parentMember); dayMember.setName(day); dayMember.setVisible(true); for (int i = 0; i <= 6; i++) { dayMember.getQueryNodes().add(sf.format(cal.getTime())); cal.add(Calendar.DATE, 1); } members.add(dayMember); // cal.add(Calendar.DATE, 1); count++; } break; case TIME_MONTHS: daysOfMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH); // cal.add(Calendar.DATE, daysOfMonth); lastDay = cal.getTime(); // lastWeek = this.getFirstDayOfWeek(lastDay); // // ??? if (nowWeek.before(lastWeek) || (nowWeek.compareTo(lastWeek) == 0)) { lastWeek = nowWeek; } cal.setTime(firstWeek); // ? while (cal.getTime().before(lastWeek) || (cal.getTime().compareTo(lastWeek) == 0)) { String day = sf.format(cal.getTime()); String caption = month + "" + count + ""; MiniCubeMember dayMember = new MiniCubeMember(day); dayMember.setCaption(caption); dayMember.setLevel(level); dayMember.setParent(parentMember); dayMember.setName(day); dayMember.setVisible(true); for (int i = 0; i <= 6; i++) { dayMember.getQueryNodes().add(sf.format(cal.getTime())); cal.add(Calendar.DATE, 1); } members.add(dayMember); // cal.add(Calendar.DATE, 1); count++; } break; case TIME_WEEKS: break; case TIME_DAYS: break; default: } return members; }
From source file:org.openossad.util.core.row.ValueDataUtil.java
public static Object weekOfYearISO8601(ValueMetaInterface metaA, Object dataA) throws OpenDESIGNERValueException { if (dataA == null) return null; if (metaA.isDate()) { Calendar calendar = Calendar.getInstance(Locale.ENGLISH); calendar.setMinimalDaysInFirstWeek(4); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(metaA.getDate(dataA)); return new Long(calendar.get(Calendar.WEEK_OF_YEAR)); }//from w w w .j a v a 2 s.c o m throw new OpenDESIGNERValueException("The 'weekOfYearISO8601' function only works with dates"); }
From source file:org.openhab.binding.lutron.internal.grxprg.PrgProtocolHandler.java
/** * Handles the report time response/*from www .j a v a2 s .c o m*/ * * @param m the non-null {@link Matcher} that matched the response * @param resp the possibly null, possibly empty actual response */ private void handleReportTime(Matcher m, String resp) { if (m == null) { throw new IllegalArgumentException("m (matcher) cannot be null"); } if (m.groupCount() == 7) { try { final Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, Integer.parseInt(m.group(1))); c.set(Calendar.MINUTE, Integer.parseInt(m.group(2))); c.set(Calendar.MONDAY, Integer.parseInt(m.group(3))); c.set(Calendar.DAY_OF_MONTH, Integer.parseInt(m.group(4))); final int yr = Integer.parseInt(m.group(5)); c.set(Calendar.YEAR, yr + (yr < 50 ? 1900 : 2000)); _callback.stateChanged(PrgConstants.CHANNEL_TIMECLOCK, new DateTimeType(c)); } catch (NumberFormatException e) { logger.error("Invalid time response (can't parse number): '{}'", resp); } } else { logger.error("Invalid time response: '{}'", resp); } }
From source file:com.panet.imeta.core.row.ValueDataUtil.java
public static Object yearOfDateISO8601(ValueMetaInterface metaA, Object dataA) throws KettleValueException { if (dataA == null) return null; if (metaA.isDate()) { Calendar calendar = Calendar.getInstance(Locale.ENGLISH); calendar.setMinimalDaysInFirstWeek(4); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(metaA.getDate(dataA)); int week = calendar.get(Calendar.WEEK_OF_YEAR); int month = calendar.get(Calendar.MONTH); int year = calendar.get(Calendar.YEAR); // fix up for the year taking into account ISO8601 weeks if (week >= 52 && month == 0) year--;//ww w . jav a2 s. co m if (week <= 2 && month == 11) year++; return new Long(year); } throw new KettleValueException("The 'yearOfDateISO8601' function only works with dates"); }
From source file:org.openossad.util.core.row.ValueDataUtil.java
public static Object yearOfDateISO8601(ValueMetaInterface metaA, Object dataA) throws OpenDESIGNERValueException { if (dataA == null) return null; if (metaA.isDate()) { Calendar calendar = Calendar.getInstance(Locale.ENGLISH); calendar.setMinimalDaysInFirstWeek(4); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(metaA.getDate(dataA)); int week = calendar.get(Calendar.WEEK_OF_YEAR); int month = calendar.get(Calendar.MONTH); int year = calendar.get(Calendar.YEAR); // fix up for the year taking into account ISO8601 weeks if (week >= 52 && month == 0) year--;/* w w w. j a v a 2s.c o m*/ if (week <= 2 && month == 11) year++; return new Long(year); } throw new OpenDESIGNERValueException("The 'yearOfDateISO8601' function only works with dates"); }