List of usage examples for java.util Calendar DAY_OF_WEEK
int DAY_OF_WEEK
To view the source code for java.util Calendar DAY_OF_WEEK.
Click Source Link
get
and set
indicating the day of the week. From source file:TimePeriod.java
/** * Gibt zurck, wie oft der bergebene Wochentag im Zeitraum vorkommt. * /*ww w .ja v a2 s.co m*/ * @param wochentag * Sonntag = 1 * @return */ public int getNumberOfWeekdays(int wochentag) { int ergebnis = 0; GregorianCalendar temp = new GregorianCalendar(); temp.setTime(from.getTime()); // Schleife ber alle Tage int aktuellerTag; while (temp.before(to)) { aktuellerTag = temp.get(Calendar.DAY_OF_WEEK); if (aktuellerTag == wochentag) ergebnis++; temp.setTimeInMillis(temp.getTimeInMillis() + ONE_DAY); } return ergebnis; }
From source file:com.espertech.esper.regression.pattern.TestCronParameter.java
private int getLastWeekDayOfMonth(Integer day, int year) { int computeDay = (day == null) ? getLastDayOfMonth(year) : day; setTime(year);//from w w w . j a v a2s.com if (!checkDayValidInMonth(computeDay, calendar.get(Calendar.MONTH), calendar.get(Calendar.YEAR))) { throw new IllegalArgumentException("Invalid day for " + calendar.get(Calendar.MONTH)); } calendar.set(Calendar.DAY_OF_MONTH, computeDay); int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); if ((dayOfWeek >= Calendar.MONDAY) && (dayOfWeek <= Calendar.FRIDAY)) { return computeDay; } if (dayOfWeek == Calendar.SATURDAY) { if (computeDay == 1) { calendar.add(Calendar.DAY_OF_MONTH, +2); } else { calendar.add(Calendar.DAY_OF_MONTH, -1); } } if (dayOfWeek == Calendar.SUNDAY) { if ((computeDay == 28) || (computeDay == 29) || (computeDay == 30) || (computeDay == 31)) { calendar.add(Calendar.DAY_OF_MONTH, -2); } else { calendar.add(Calendar.DAY_OF_MONTH, +2); } } return calendar.get(Calendar.DAY_OF_MONTH); }
From source file:com.pr7.logging.CustomDailyRollingFileAppender.java
public Date getNextCheckDate(Date now) { this.setTime(now); switch (type) { case CustomDailyRollingFileAppender.TOP_OF_MINUTE: this.set(Calendar.SECOND, 0); this.set(Calendar.MILLISECOND, 0); this.add(Calendar.MINUTE, 1); break;/*from ww w . j a v a 2s.c o m*/ case CustomDailyRollingFileAppender.TOP_OF_HOUR: this.set(Calendar.MINUTE, 0); this.set(Calendar.SECOND, 0); this.set(Calendar.MILLISECOND, 0); this.add(Calendar.HOUR_OF_DAY, 1); break; case CustomDailyRollingFileAppender.HALF_DAY: this.set(Calendar.MINUTE, 0); this.set(Calendar.SECOND, 0); this.set(Calendar.MILLISECOND, 0); int hour = get(Calendar.HOUR_OF_DAY); if (hour < 12) { this.set(Calendar.HOUR_OF_DAY, 12); } else { this.set(Calendar.HOUR_OF_DAY, 0); this.add(Calendar.DAY_OF_MONTH, 1); } break; case CustomDailyRollingFileAppender.TOP_OF_DAY: this.set(Calendar.HOUR_OF_DAY, 0); this.set(Calendar.MINUTE, 0); this.set(Calendar.SECOND, 0); this.set(Calendar.MILLISECOND, 0); this.add(Calendar.DATE, 1); break; case CustomDailyRollingFileAppender.TOP_OF_WEEK: this.set(Calendar.DAY_OF_WEEK, getFirstDayOfWeek()); this.set(Calendar.HOUR_OF_DAY, 0); this.set(Calendar.MINUTE, 0); this.set(Calendar.SECOND, 0); this.set(Calendar.MILLISECOND, 0); this.add(Calendar.WEEK_OF_YEAR, 1); break; case CustomDailyRollingFileAppender.TOP_OF_MONTH: this.set(Calendar.DATE, 1); this.set(Calendar.HOUR_OF_DAY, 0); this.set(Calendar.MINUTE, 0); this.set(Calendar.SECOND, 0); this.set(Calendar.MILLISECOND, 0); this.add(Calendar.MONTH, 1); break; default: throw new IllegalStateException("Unknown periodicity type."); } return getTime(); }
From source file:com.panet.imeta.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java
public static Object getDayNumber(Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext) { if (ArgList.length == 2) { try {/*from w w w . j a va 2s .c o m*/ if (isNull(ArgList[0])) return new Double(Double.NaN); else if (isUndefined(ArgList[0])) return Context.getUndefinedValue(); else { java.util.Date dIn = (java.util.Date) Context.jsToJava(ArgList[0], java.util.Date.class); String strType = Context.toString(ArgList[1]); Calendar startDate = Calendar.getInstance(); startDate.setTime(dIn); if (strType.toLowerCase().equals("y")) return new Double(startDate.get(Calendar.DAY_OF_YEAR)); else if (strType.toLowerCase().equals("m")) return new Double(startDate.get(Calendar.DAY_OF_MONTH)); else if (strType.toLowerCase().equals("w")) return new Double(startDate.get(Calendar.DAY_OF_WEEK)); else if (strType.toLowerCase().equals("wm")) return new Double(startDate.get(Calendar.DAY_OF_WEEK_IN_MONTH)); else if (strType.toLowerCase().equals("l")) return new Long(startDate.getTimeInMillis()); return new Double(startDate.get(Calendar.DAY_OF_YEAR)); } } catch (Exception e) { return null; //throw Context.reportRuntimeError(e.toString()); } } else { throw Context.reportRuntimeError("The function call getDayNumber requires 2 arguments."); } }
From source file:com.hihframework.core.utils.DateUtils.java
public static String getDateString(java.util.Date date) { if (date == null) { return ""; }//from w w w .jav a 2 s . c o m String result = ""; cal.setTime(new java.util.Date(date.getTime())); int _year = cal.get(Calendar.YEAR); int _month = cal.get(Calendar.MONTH) + 1; int _date = cal.get(Calendar.DATE); int _week = cal.get(Calendar.DAY_OF_WEEK) - 1; result += (_year + "" + _month + "" + _date + "" + " " + WeekCn[_week]); return result; }
From source file:org.everit.jira.timetracker.plugin.JiraTimetrackerPluginImpl.java
@Override public Date firstMissingWorklogsDate(final String selectedUser) throws GenericEntityException { Calendar scannedDate = Calendar.getInstance(); // one week//from ww w . j ava2s . co m scannedDate.set(Calendar.DAY_OF_YEAR, scannedDate.get(Calendar.DAY_OF_YEAR) - DateTimeConverterUtil.DAYS_PER_WEEK); for (int i = 0; i < DateTimeConverterUtil.DAYS_PER_WEEK; i++) { // convert date to String Date scanedDateDate = scannedDate.getTime(); String scanedDateString = DateTimeConverterUtil.dateToString(scanedDateDate); // check excludse - pass if (excludeDatesSet.contains(scanedDateString)) { scannedDate.set(Calendar.DAY_OF_YEAR, scannedDate.get(Calendar.DAY_OF_YEAR) + 1); continue; } // check includes - not check weekend // check weekend - pass if (!includeDatesSet.contains(scanedDateString) && ((scannedDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) || (scannedDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY))) { scannedDate.set(Calendar.DAY_OF_YEAR, scannedDate.get(Calendar.DAY_OF_YEAR) + 1); continue; } // check worklog. if no worklog set result else ++ scanedDate boolean isDateContainsWorklog = isContainsWorklog(scanedDateDate); if (!isDateContainsWorklog) { return scanedDateDate; } else { scannedDate.set(Calendar.DAY_OF_YEAR, scannedDate.get(Calendar.DAY_OF_YEAR) + 1); } } // if we find everything all right then return with the current date return scannedDate.getTime(); }
From source file:com.akretion.kettle.steps.terminatooor.ScriptValuesAddedFunctions.java
public static Object isWorkingDay(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext) { if (ArgList.length == 1) { try {//from w w w.ja va 2s . c o m if (isNull(ArgList[0])) return null; else if (isUndefined(ArgList[0])) return undefinedValue; else { java.util.Date dIn = (java.util.Date) ArgList[0]; Calendar startDate = Calendar.getInstance(); startDate.setTime(dIn); if (startDate.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY && startDate.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) return Boolean.TRUE; return Boolean.FALSE; } } catch (Exception e) { return null; } } else { throw new RuntimeException("The function call isWorkingDay requires 1 argument."); } }
From source file:com.espertech.esper.regression.pattern.TestCronParameter.java
private int getDayOfWeek(int day, int year) { setTime(year);/*from ww w. ja v a2 s. c o m*/ calendar.set(Calendar.DAY_OF_WEEK, day + 1); return calendar.get(Calendar.DAY_OF_WEEK); }
From source file:Holidays.java
public static java.util.Calendar ThanksgivingObserved(int nYear) { int nX;/*from w ww . j a v a2 s . co m*/ int nMonth = 10; // November java.util.Calendar cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 1); nX = cal.get(Calendar.DAY_OF_WEEK); switch (nX) { case 0: {// Sunday cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 26); return cal; } case 1: {// Monday cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 25); return cal; } case 2: // Tuesday { cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 24); return cal; } case 3: // Wednesday { cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 23); return cal; } case 4: // Thrusday { cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 22); return cal; } case 5: // Friday { cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 28); return cal; } default: // Saturday { cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 27); return cal; } } }
From source file:com.frey.repo.DateUtil.java
/***************************************** * @ ??/* www . jav a 2 s . c om*/ ****************************************/ public static String getYearWeekFirstDay(Date curDate) { Calendar cal = Calendar.getInstance(); cal.setTime(curDate); if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { cal.set(Calendar.WEEK_OF_YEAR, cal.get(Calendar.WEEK_OF_YEAR) - 1); } else { cal.set(Calendar.WEEK_OF_YEAR, cal.get(Calendar.WEEK_OF_YEAR)); } cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); String tempYear = Integer.toString(cal.get(Calendar.YEAR)); String tempMonth = Integer.toString(cal.get(Calendar.MONTH) + 1); String tempDay = Integer.toString(cal.get(Calendar.DATE)); String tempDate = tempYear + "-" + tempMonth + "-" + tempDay; return setDateFormat(tempDate, "yyyy-MM-dd"); }