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:org.activequant.util.charting.IntradayMarketTimeline.java
/** * Translates a value relative to this timeline into a domain value. The * domain value obtained by this method is not always the same domain value * that could have been supplied to//www .j av a 2 s . c om * translateDomainValueToTimelineValue(domainValue). * This is because the original tranformation may not be complete * reversable. * * @see org.jfree.chart.axis.SegmentedTimeline * * @param timelineValue a timeline value. * * @return A domain value. */ public long toMillisecond(long timelineValue) { if (this.activeTimePerWeek == 0L) return 0; //starting from Jan 1, 1970 work backwards. //find out the number of whole weeks in the timelineValue Long l = new Long(timelineValue / this.activeTimePerWeek); int numWeeks = (int) Math.floor(l.doubleValue()); //the amount of time left on the timeline from the last thursday long timeLeftSinceThursday = timelineValue - (numWeeks * this.activeTimePerWeek); int day = Calendar.THURSDAY; int numDays = 0; //from last friday until the current day //if the amount of time left is greater than //the active time for that day, increment the number of //days and subtract from the time left while (numDays < 7) { if (day == Calendar.SUNDAY) { if (timeLeftSinceThursday > this.sundayActive) { timeLeftSinceThursday -= this.sundayActive; numDays++; } else { break; } } else if (day == Calendar.MONDAY) { if (timeLeftSinceThursday > this.mondayActive) { timeLeftSinceThursday -= this.mondayActive; numDays++; } else { break; } } else if (day == Calendar.TUESDAY) { if (timeLeftSinceThursday > this.tuesdayActive) { timeLeftSinceThursday -= this.tuesdayActive; numDays++; } else { break; } } else if (day == Calendar.WEDNESDAY) { if (timeLeftSinceThursday > this.wednesdayActive) { timeLeftSinceThursday -= this.wednesdayActive; numDays++; } else { break; } } else if (day == Calendar.THURSDAY) { if (timeLeftSinceThursday > this.thursdayActive) { timeLeftSinceThursday -= this.thursdayActive; numDays++; //thursday numDays = " + Integer.toString(numDays)); } else { break; } } else if (day == Calendar.FRIDAY) { if (timeLeftSinceThursday > this.fridayActive) { timeLeftSinceThursday -= this.fridayActive; numDays++; } else { break; } } else if (day == Calendar.SATURDAY) { if (timeLeftSinceThursday > this.saturdayActive) { timeLeftSinceThursday -= this.saturdayActive; numDays++; } else { break; } } day = this.nextDay(day); } long millis = numWeeks * MILLIS_PER_WEEK + numDays * MILLIS_PER_DAY + this.getStartTime(day) + timeLeftSinceThursday; return millis; }
From source file:org.nuclos.common2.DateUtils.java
private static void calc(GregorianCalendar result, CalcFunction cf, CalcPair cp) { switch (cf) { case ADD://from w w w . j a va 2s . c o m result.add(cp.x, cp.y); break; case SUBTRACT: result.add(cp.x, cp.y * (-1)); break; case SET: switch (cp.x) { case Calendar.YEAR: result.set(Calendar.DAY_OF_YEAR, cp.y == Integer.MIN_VALUE ? result.getActualMinimum(Calendar.DAY_OF_YEAR) : result.getActualMaximum(Calendar.DAY_OF_YEAR)); break; case Calendar.MONTH: result.set(Calendar.DAY_OF_MONTH, cp.y == Integer.MIN_VALUE ? result.getActualMinimum(Calendar.DAY_OF_MONTH) : result.getActualMaximum(Calendar.DAY_OF_MONTH)); break; case Calendar.WEEK_OF_YEAR: result.set(Calendar.DAY_OF_WEEK, cp.y == Integer.MIN_VALUE ? Calendar.MONDAY : Calendar.SUNDAY); break; } break; } }
From source file:eionet.util.Util.java
/** * A method for calculating time difference in MILLISECONDS, between a date-time specified in input parameters and the current * date-time. <BR>/*w ww . j a v a 2s. c o m*/ * This should be useful for calculating sleep time for code that has a certain schedule for execution. * * @param hour * An integer from 0 to 23. If less than 0 or more than 23, then the closest next hour to current hour is taken. * @param date * An integer from 1 to 31. If less than 1 or more than 31, then the closest next date to current date is taken. * @param month * An integer from Calendar.JANUARY to Calendar.DECEMBER. If out of those bounds, the closest next month to current * month is taken. * @param wday * An integer from 1 to 7. If out of those bounds, the closest next weekday to weekday month is taken. * @param zone * A String specifying the time-zone in which the calculations should be done. Please see Java documentation an * allowable time-zones and formats. * @return Time difference in milliseconds. */ public static long timeDiff(int hour, int date, int month, int wday, String zone) { GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone(zone)); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); cal.setFirstDayOfWeek(Calendar.MONDAY); /* * here we force the hour to be one of the defualts if (hour < 0) hour = 0; if (hour > 23) hour = 23; */ int cur_hour = cal.get(Calendar.HOUR); if (cal.get(Calendar.AM_PM) == Calendar.PM) { cur_hour = 12 + cur_hour; } // here we assume that every full hour is accepted /* * if (hour < 0 || hour > 23) { hour = cur_hour>=23 ? 0 : cur_hour + 1; } */ if (wday >= 1 && wday <= 7) { int cur_wday = cal.get(Calendar.DAY_OF_WEEK); if (hour < 0 || hour > 23) { if (cur_wday != wday) { hour = 0; } else { hour = cur_hour >= 23 ? 0 : cur_hour + 1; } } int amount = wday - cur_wday; if (amount < 0) { amount = 7 + amount; } if (amount == 0 && cur_hour >= hour) { amount = 7; } cal.add(Calendar.DAY_OF_WEEK, amount); } else if (month >= Calendar.JANUARY && month <= Calendar.DECEMBER) { // do something about when every date is accepted if (date < 1) { date = 1; } if (date > 31) { date = 31; } int cur_month = cal.get(Calendar.MONTH); int amount = month - cur_month; if (amount < 0) { amount = 12 + amount; } if (amount == 0) { if (cal.get(Calendar.DATE) > date) { amount = 12; } else if (cal.get(Calendar.DATE) == date) { if (cur_hour >= hour) { amount = 12; } } } // cal.set(Calendar.DATE, date); cal.add(Calendar.MONTH, amount); if (date > cal.getActualMaximum(Calendar.DATE)) { date = cal.getActualMaximum(Calendar.DATE); } cal.set(Calendar.DATE, date); } else if (date >= 1 && date <= 31) { int cur_date = cal.get(Calendar.DATE); if (cur_date > date) { cal.add(Calendar.MONTH, 1); } else if (cur_date == date) { if (cur_hour >= hour) { cal.add(Calendar.MONTH, 1); } } cal.set(Calendar.DATE, date); } else { if (hour < 0 || hour > 23) { hour = cur_hour >= 23 ? 0 : cur_hour + 1; } if (cur_hour >= hour) { cal.add(Calendar.DATE, 1); } } if (hour >= 12) { cal.set(Calendar.HOUR, hour - 12); cal.set(Calendar.AM_PM, Calendar.PM); } else { cal.set(Calendar.HOUR, hour); cal.set(Calendar.AM_PM, Calendar.AM); } Date nextDate = cal.getTime(); Date currDate = new Date(); long nextTime = cal.getTime().getTime(); long currTime = (new Date()).getTime(); return nextTime - currTime; }
From source file:com.baidu.rigel.biplatform.tesseract.meta.impl.TimeDimensionMemberServiceImpl.java
/** * ??/*from ww w . ja v a 2s. co m*/ * * @param date * @return */ private Date getFirstDayOfWeek(Date date) { Calendar cal = Calendar.getInstance(); cal.setFirstDayOfWeek(Calendar.MONDAY); cal.setTime(date); cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); return cal.getTime(); }
From source file:com.autentia.intra.bean.activity.ObjectiveBean.java
/** * Move a date to one of its surrounding fridays. * * @param d the reference date/*from w w w . j a v a 2 s . com*/ * @param inFuture whether to move to future/previous friday * @return the requested friday */ private Date moveToFriday(Date d, boolean inFuture) { Calendar cal = Calendar.getInstance(); cal.setTime(d); switch (cal.get(Calendar.DAY_OF_WEEK)) { case Calendar.MONDAY: cal.add(Calendar.DAY_OF_WEEK, inFuture ? 4 : -3); break; case Calendar.TUESDAY: cal.add(Calendar.DAY_OF_WEEK, inFuture ? 3 : -4); break; case Calendar.WEDNESDAY: cal.add(Calendar.DAY_OF_WEEK, inFuture ? 2 : -5); break; case Calendar.THURSDAY: cal.add(Calendar.DAY_OF_WEEK, inFuture ? 1 : -6); break; case Calendar.FRIDAY: cal.add(Calendar.DAY_OF_WEEK, inFuture ? 0 : -7); break; case Calendar.SATURDAY: cal.add(Calendar.DAY_OF_WEEK, inFuture ? 6 : -1); break; case Calendar.SUNDAY: cal.add(Calendar.DAY_OF_WEEK, inFuture ? 5 : -2); break; } return cal.getTime(); }
From source file:de.tap.easy_xkcd.utils.PrefHelper.java
public boolean checkUpdated(int day) { switch (day) { case Calendar.MONDAY: return sharedPrefs.getBoolean(MONDAY_UPDATE, false); case Calendar.WEDNESDAY: return sharedPrefs.getBoolean(WEDNESDAY_UPDATE, false); case Calendar.FRIDAY: return sharedPrefs.getBoolean(FRIDAY_UPDATE, false); case Calendar.TUESDAY: return sharedPrefs.getBoolean(TUESDAY_UPDATE, false); }//from w w w .ja va 2s. c o m return true; }
From source file:de.tap.easy_xkcd.utils.PrefHelper.java
public void setUpdated(int day, boolean found) { SharedPreferences.Editor editor = sharedPrefs.edit(); switch (day) { case Calendar.MONDAY: editor.putBoolean(MONDAY_UPDATE, found); editor.putBoolean(WEDNESDAY_UPDATE, false); editor.putBoolean(FRIDAY_UPDATE, false); break;/* w ww .jav a 2s. c o m*/ case Calendar.WEDNESDAY: editor.putBoolean(WEDNESDAY_UPDATE, found); editor.putBoolean(FRIDAY_UPDATE, false); editor.putBoolean(MONDAY_UPDATE, false); editor.putBoolean(TUESDAY_UPDATE, false); break; case Calendar.FRIDAY: editor.putBoolean(FRIDAY_UPDATE, found); editor.putBoolean(MONDAY_UPDATE, false); editor.putBoolean(WEDNESDAY_UPDATE, false); editor.putBoolean(TUESDAY_UPDATE, false); break; case Calendar.TUESDAY: editor.putBoolean(TUESDAY_UPDATE, found); } editor.apply(); Log.d("Update Status:", String.valueOf(sharedPrefs.getBoolean(MONDAY_UPDATE, false)) + String.valueOf(sharedPrefs.getBoolean(TUESDAY_UPDATE, false)) + String.valueOf(sharedPrefs.getBoolean(WEDNESDAY_UPDATE, false)) + String.valueOf(sharedPrefs.getBoolean(FRIDAY_UPDATE, false))); }
From source file:org.kuali.coeus.common.committee.impl.bo.CommitteeScheduleBase.java
/** * This UI support method to find day Of week from BO's persistent field scheduledDate. * @return/*from w w w . j a v a 2 s .c o m*/ */ public String getDayOfWeek() { Calendar cl = new GregorianCalendar(); cl.setTime(scheduledDate); DayOfWeek dayOfWeek = null; switch (cl.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: dayOfWeek = DayOfWeek.Sunday; break; case Calendar.MONDAY: dayOfWeek = DayOfWeek.Monday; break; case Calendar.TUESDAY: dayOfWeek = DayOfWeek.Tuesday; break; case Calendar.WEDNESDAY: dayOfWeek = DayOfWeek.Wednesday; break; case Calendar.THURSDAY: dayOfWeek = DayOfWeek.Thursday; break; case Calendar.FRIDAY: dayOfWeek = DayOfWeek.Friday; break; case Calendar.SATURDAY: dayOfWeek = DayOfWeek.Saturday; break; } return dayOfWeek.name().toUpperCase(); }
From source file:org.squale.welcom.outils.Util.java
public static Date getLastMonday() { java.util.Date jour = new java.util.Date(); final Calendar cal = new GregorianCalendar(); cal.setTime(jour);/*from w w w .java2 s . c om*/ while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { jour = new java.util.Date(jour.getTime() - (24 * 60 * 60)); cal.setTime(jour); } return jour; }
From source file:com.baifendian.swordfish.execserver.parameter.placeholder.TimePlaceholderUtil.java
/** * ? <p>/*from w w w .j av 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(); }