List of usage examples for org.joda.time DateTime getDayOfWeek
public int getDayOfWeek()
From source file:com.inkubator.hrm.web.converter.DayAsStringConverter.java
@Override public String getAsString(FacesContext context, UIComponent component, Object value) { DateTime dt = new DateTime((Date) value); int dayOFWeek = dt.getDayOfWeek() == 7 ? 1 : dt.getDayOfWeek() + 1; DateFormatSymbols dfs = new DateFormatSymbols( new Locale(FacesUtil.getSessionAttribute(HRMConstant.BAHASA_ACTIVE).toString())); return dfs.getWeekdays()[dayOFWeek]; }
From source file:com.jgoetsch.tradeframework.marketdata.HistoricalMarketDataFeed.java
License:Apache License
/** * Overridable method to adjust a timestamp to the next regular trading session * of the given contract if it falls outside of the contract's regular trading hours. * /*from www. j a v a 2 s. c om*/ * @param timestamp * @param contract * @return millisecond timestamp adjusted up to a regular trading session. */ protected long adjustTimestampToRTH(long timestamp, Contract contract) { if ("STK".equals(contract.getType()) && "USD".equals(contract.getCurrency())) { DateTime dt = new DateTime(timestamp, DateTimeZone.forID("America/New_York")); LocalTime time = new LocalTime(dt); if (time.compareTo(new LocalTime(9, 30)) < 0) dt = dt.withHourOfDay(9).withMinuteOfHour(30); else if (time.compareTo(new LocalTime(16, 0)) >= 0) { dt = dt.plusDays(1).withHourOfDay(9).withMinuteOfHour(30); } if (dt.getDayOfWeek() == DateTimeConstants.SATURDAY) dt = dt.plusDays(2); else if (dt.getDayOfWeek() == DateTimeConstants.SUNDAY) dt = dt.plusDays(1); return dt.getMillis(); } else if ("FUT".equals(contract.getType()) && "USD".equals(contract.getCurrency())) { DateTime dt = new DateTime(timestamp, DateTimeZone.forID("America/Chicago")); if (dt.getDayOfWeek() == DateTimeConstants.SATURDAY) dt = dt.plusDays(2).withHourOfDay(9).withMinuteOfHour(0); else if (dt.getDayOfWeek() == DateTimeConstants.SUNDAY) dt = dt.plusDays(1).withHourOfDay(9).withMinuteOfHour(0); return dt.getMillis(); } else return timestamp; }
From source file:com.jive.myco.seyren.core.domain.Subscription.java
License:Apache License
private boolean isCorrectDayOfWeek(DateTime time) { int day = time.getDayOfWeek(); if (day == 1 && isMo()) return true; if (day == 2 && isTu()) return true; if (day == 3 && isWe()) return true; if (day == 4 && isTh()) return true; if (day == 5 && isFr()) return true; if (day == 6 && isSa()) return true; if (day == 7 && isSu()) return true; return false; }
From source file:com.kopysoft.chronos.adapter.clock.PayPeriodAdapterList.java
License:Open Source License
public DurationHolder getTime(WeekendOverride sat, WeekendOverride sun) { DurationHolder durHolder = new DurationHolder(); for (DateTime date : gPunchesByDay.getDays()) { if (date.getDayOfWeek() == DateTimeConstants.SATURDAY && sat != WeekendOverride.NONE) { Duration temp = getTime(gPunchesByDay.getPunchPair(date)); durHolder.addSaturdayPay(date.toDateMidnight(), temp); } else if (date.getDayOfWeek() == DateTimeConstants.SUNDAY && sun != WeekendOverride.NONE) { Duration temp = getTime(gPunchesByDay.getPunchPair(date)); durHolder.addSundayPay(date.toDateMidnight(), temp); } else {//from ww w . jav a 2s . c o m Duration temp = getTime(gPunchesByDay.getPunchPair(date)); durHolder.addNormalPay(date.toDateMidnight(), temp); } } return durHolder; }
From source file:com.lostrealm.lembretes.DownloadJob.java
License:Open Source License
static void scheduleExact() { DateTime time = DateTime.now(); if (time.getHourOfDay() > 20) time.plusDays(1);//from w w w. j av a 2 s.c o m if (time.getDayOfWeek() == DateTimeConstants.SATURDAY) time.plusDays(2); else if (time.getDayOfWeek() == DateTimeConstants.SUNDAY) time.plusDays(1); scheduleExact(time.toString("yyyy-MM?dd")); }
From source file:com.lostrealm.lembretes.MealManager.java
License:Open Source License
Meal getMeal(Context context) { boolean vegetarian = PreferenceManager.getDefaultSharedPreferences(context) .getBoolean(context.getString(R.string.pref_menu_key), false); // TODO: account for holidays DateTime time = DateTime.now(); if (time.getDayOfWeek() == DateTimeConstants.SATURDAY || time.getDayOfWeek() == DateTimeConstants.SUNDAY || time.getHourOfDay() < 16) return meals.get(!vegetarian ? 0 : 1); return meals.get(!vegetarian ? 2 : 3); }
From source file:com.marand.thinkmed.medications.business.impl.MedicationsEhrUtils.java
License:Open Source License
public static DayOfWeek dayOfWeekToEhrEnum(final DateTime dateTime) { if (dateTime.getDayOfWeek() == DateTimeConstants.MONDAY) { return DayOfWeek.MONDAY; }// ww w . j ava2 s . c o m if (dateTime.getDayOfWeek() == DateTimeConstants.TUESDAY) { return DayOfWeek.TUESDAY; } if (dateTime.getDayOfWeek() == DateTimeConstants.WEDNESDAY) { return DayOfWeek.WEDNESDAY; } if (dateTime.getDayOfWeek() == DateTimeConstants.THURSDAY) { return DayOfWeek.THURSDAY; } if (dateTime.getDayOfWeek() == DateTimeConstants.FRIDAY) { return DayOfWeek.FRIDAY; } if (dateTime.getDayOfWeek() == DateTimeConstants.SATURDAY) { return DayOfWeek.SATURDAY; } if (dateTime.getDayOfWeek() == DateTimeConstants.SUNDAY) { return DayOfWeek.SUNDAY; } throw new IllegalArgumentException("Day of week conversion error"); }
From source file:com.microsoft.exchange.utils.TimeZoneHelper.java
License:Open Source License
private static SerializableTimeZoneTime toSerializableTimeZoneTime(DateTimeZone zone, long transition) { int standardOffset = zone.getStandardOffset(transition); long offset = zone.getOffset(transition); int bias = toBias(offset - standardOffset); DateTime time = new DateTime(transition, zone); short month = (short) time.getMonthOfYear(); short day = (short) time.getDayOfMonth(); DayOfWeekType dayOfWeek = toDayOfWeek(time.getDayOfWeek()); return new SerializableTimeZoneTime(bias, time.toString("HH:mm:ss"), day, month, dayOfWeek, time.toString("yyyy")); }
From source file:com.microsoft.office365.snippetapp.Snippets.CalendarSnippets.java
License:MIT License
/** * Creates a recurring event. This snippet will create an event that recurs * every Tuesday and Thursday from 1PM to 2PM. You can modify this snippet * to work with other recurrence patterns. * * @param subject The subject of the event * @param itemBodyHtml The body of the event as HTML * @param attendees A list of attendee email addresses * @return String The id of the created event *//*from w w w . j a v a 2s .co m*/ public String createRecurringCalendarEvent(String subject, String itemBodyHtml, List<String> attendees) throws ExecutionException, InterruptedException { //Create a new Office 365 Event object Event newEvent = new Event(); newEvent.setSubject(subject); ItemBody itemBody = new ItemBody(); itemBody.setContent(itemBodyHtml); itemBody.setContentType(BodyType.HTML); newEvent.setBody(itemBody); //Set the attendee list List<Attendee> attendeeList = convertEmailStringsToAttendees(attendees); newEvent.setAttendees(attendeeList); //Set start date to the next occurring Tuesday DateTime startDate = DateTime.now(); if (startDate.getDayOfWeek() < DateTimeConstants.TUESDAY) { startDate = startDate.dayOfWeek().setCopy(DateTimeConstants.TUESDAY); } else { startDate = startDate.plusWeeks(1); startDate = startDate.dayOfWeek().setCopy(DateTimeConstants.TUESDAY); } //Set start time to 1 PM startDate = startDate.hourOfDay().setCopy(13).withMinuteOfHour(0).withSecondOfMinute(0) .withMillisOfSecond(0); //Set end time to 2 PM DateTime endDate = startDate.hourOfDay().setCopy(14); //Set start and end time on the new Event (next Tuesday 1-2PM) newEvent.setStart(startDate.toCalendar(Locale.getDefault())); newEvent.setIsAllDay(false); newEvent.setEnd(endDate.toCalendar(Locale.getDefault())); //Configure the recurrence pattern for the new event //In this case the meeting will occur every Tuesday and Thursday from 1PM to 2PM RecurrencePattern recurrencePattern = new RecurrencePattern(); List<DayOfWeek> daysMeetingRecursOn = new ArrayList(); daysMeetingRecursOn.add(DayOfWeek.Tuesday); daysMeetingRecursOn.add(DayOfWeek.Thursday); recurrencePattern.setType(RecurrencePatternType.Weekly); recurrencePattern.setDaysOfWeek(daysMeetingRecursOn); recurrencePattern.setInterval(1); //recurs every week //Create a recurring range. In this case the range does not end //and the event occurs every Tuesday and Thursday forever. RecurrenceRange recurrenceRange = new RecurrenceRange(); recurrenceRange.setType(RecurrenceRangeType.NoEnd); recurrenceRange.setStartDate(startDate.toCalendar(Locale.getDefault())); //Create a pattern of recurrence. It contains the recurrence pattern //and recurrence range created previously. PatternedRecurrence patternedRecurrence = new PatternedRecurrence(); patternedRecurrence.setPattern(recurrencePattern); patternedRecurrence.setRange(recurrenceRange); //Finally pass the patterned recurrence to the new Event object. newEvent.setRecurrence(patternedRecurrence); //Create the event and return the id return mCalendarClient.getMe().getEvents().select("ID").add(newEvent).get().getId(); }
From source file:com.money.manager.ex.servicelayer.RecurringTransactionService.java
License:Open Source License
/** * @param date to start calculate/*from w ww.j a v a 2 s . c o m*/ * @param repeatType type of repeating transactions * @param numberOfPeriods Number of instances (days, months) parameter. Used for In (x) Days, for * example to indicate x. * @return next Date */ public DateTime getNextScheduledDate(DateTime date, Recurrence repeatType, Integer numberOfPeriods) { if (numberOfPeriods == null || numberOfPeriods == Constants.NOT_SET) { numberOfPeriods = 0; } if (repeatType.getValue() >= 200) { repeatType = Recurrence.valueOf(repeatType.getValue() - 200); } // set auto execute without user acknowledgement if (repeatType.getValue() >= 100) { repeatType = Recurrence.valueOf(repeatType.getValue() - 100); } // set auto execute on the next occurrence DateTime result = new DateTime(date); switch (repeatType) { case ONCE: //none break; case WEEKLY: //weekly result = result.plusWeeks(1); break; case BIWEEKLY: //bi_weekly result = result.plusWeeks(2); break; case MONTHLY: //monthly result = result.plusMonths(1); break; case BIMONTHLY: //bi_monthly result = result.plusMonths(2); break; case QUARTERLY: //quarterly result = result.plusMonths(3); break; case SEMIANNUALLY: //half_year result = result.plusMonths(6); break; case ANNUALLY: //yearly result = result.plusYears(1); break; case FOUR_MONTHS: //four_months result = result.plusMonths(4); break; case FOUR_WEEKS: //four_weeks result = result.plusWeeks(4); break; case DAILY: //daily result = result.plusDays(1); break; case IN_X_DAYS: //in_x_days case EVERY_X_DAYS: //every_x_days result = result.plusDays(numberOfPeriods); break; case IN_X_MONTHS: //in_x_months case EVERY_X_MONTHS: //every_x_months result = result.plusMonths(numberOfPeriods); break; case MONTHLY_LAST_DAY: //month (last day) // if the date is not the last day of this month, set it to the end of the month. // else set it to the end of the next month. DateTime lastDayOfMonth = MmxDateTimeUtils.getLastDayOfMonth(result); if (!result.equals(lastDayOfMonth)) { // set to last day of the month result = lastDayOfMonth; } else { result = lastDayOfMonth.plusMonths(1); } break; case MONTHLY_LAST_BUSINESS_DAY: //month (last business day) // if the date is not the last day of this month, set it to the end of the month. // else set it to the end of the next month. DateTime lastDayOfMonth2 = MmxDateTimeUtils.getLastDayOfMonth(result); if (!result.equals(lastDayOfMonth2)) { // set to last day of the month result = lastDayOfMonth2; } else { result = lastDayOfMonth2.plusMonths(1); } // get the last day of the next month, // then iterate backwards until we are on a weekday. while (result.getDayOfWeek() == DateTimeConstants.SATURDAY || result.getDayOfWeek() == DateTimeConstants.SUNDAY) { result = result.minusDays(1); } break; } return result; }