List of usage examples for org.joda.time DateTime getDayOfMonth
public int getDayOfMonth()
From source file:rapture.common.USCalendar.java
License:Open Source License
public static boolean isHoliday(DateTime date) { String key = String.format("%d/%d", date.getMonthOfYear(), date.getDayOfMonth()); return HOLIDAYS.containsKey(key); }
From source file:rapture.event.generator.EventGenerator.java
License:Open Source License
private static void generatePeriodic(List<String> ret, DateTime dt, boolean periodic) { // We guarantee that each call to this function, cal will be advanced a // minute at least int dayOfWeek = dt.getDayOfWeek(); if (periodic) { checkAdd(dayOfWeek, dt.getMinuteOfHour(), minuteChecks, "minutes", "/time", ret); if (dt.getMinuteOfHour() == 0) { checkAdd(dayOfWeek, dt.getHourOfDay(), hourChecks, "hours", "/time", ret); if (dt.getHourOfDay() == 0) { ret.add("/time/days" + dt.getDayOfMonth()); if (dt.getDayOfMonth() == 1) { ret.add("/time/months" + dt.getMonthOfYear()); }/*from w w w . j a v a 2 s .co m*/ } } } // We construct, for each supported timezone, // timezone/daily/[timezone]/hour/minute // timezone/weekend/ (if a weekend) // timezone/weekeday/ (if a weekday) // timezone/day // So initially create the end point for each timezone, then push it out // We assume dt is in UT (but does this matter?) for (Map.Entry<String, DateTimeZone> zoneEntry : timeZones.entrySet()) { DateTime dtLocal = dt.withZone(zoneEntry.getValue()); String convertedZone = getConvertedTimeZone(zoneEntry.getKey()); int localDow = dtLocal.getDayOfWeek(); String endField = hmFormat.print(dtLocal); ret.add(String.format("/timezone/daily/%s/%s", convertedZone, endField)); ret.add(String.format("/timezone/%s/%s/%s", isWeekend(localDow) ? "weekend" : "weekday", convertedZone, endField)); ret.add(String.format("/timezone/%s/%s/%s", getDOWName(localDow), convertedZone, endField)); } }
From source file:ru.touchin.templates.calendar.CalendarUtils.java
License:Apache License
/** * Create list of {@link CalendarItem} according to start and end Dates. * * @param startDate Start date of the range; * @param endDate End date of the range; * @return List of CalendarItems that could be one of these: {@link CalendarHeaderItem}, {@link CalendarDayItem} or {@link CalendarEmptyItem}. *//*from ww w .j a v a 2 s. c om*/ @NonNull @SuppressWarnings("checkstyle:MethodLength") public static List<CalendarItem> fillRanges(@NonNull final DateTime startDate, @NonNull final DateTime endDate) { final DateTime cleanStartDate = startDate.withTimeAtStartOfDay(); final DateTime cleanEndDate = endDate.plusDays(1).withTimeAtStartOfDay(); DateTime tempTime = cleanStartDate; final List<CalendarItem> calendarItems = fillCalendarTillCurrentDate(cleanStartDate, tempTime); tempTime = tempTime.plusDays(Days.ONE.getDays()); final int totalDaysCount = Days.daysBetween(tempTime, cleanEndDate).getDays(); int shift = calendarItems.get(calendarItems.size() - 1).getEndRange(); int firstDate = tempTime.getDayOfMonth() - 1; int daysEnded = 1; while (true) { final int daysInCurrentMonth = tempTime.dayOfMonth().getMaximumValue(); final long firstRangeDate = tempTime.getMillis(); if ((daysEnded + (daysInCurrentMonth - firstDate)) <= totalDaysCount) { tempTime = tempTime.plusMonths(1).withDayOfMonth(1); calendarItems.add(new CalendarDayItem(firstRangeDate, firstDate + 1, shift + daysEnded, shift + daysEnded + (daysInCurrentMonth - firstDate) - 1, ComparingToToday.AFTER_TODAY)); daysEnded += daysInCurrentMonth - firstDate; if (daysEnded == totalDaysCount) { break; } firstDate = 0; final int firstDayInWeek = tempTime.getDayOfWeek() - 1; if (firstDayInWeek != 0) { calendarItems.add(new CalendarEmptyItem(shift + daysEnded, shift + daysEnded + (DAYS_IN_WEEK - firstDayInWeek - 1))); shift += (DAYS_IN_WEEK - firstDayInWeek); } calendarItems.add(new CalendarHeaderItem(tempTime.getYear(), tempTime.getMonthOfYear() - 1, shift + daysEnded, shift + daysEnded)); shift += 1; if (firstDayInWeek != 0) { calendarItems .add(new CalendarEmptyItem(shift + daysEnded, shift + daysEnded + firstDayInWeek - 1)); shift += firstDayInWeek; } } else { calendarItems.add(new CalendarDayItem(firstRangeDate, firstDate + 1, shift + daysEnded, shift + totalDaysCount, ComparingToToday.AFTER_TODAY)); break; } } return calendarItems; }
From source file:ru.touchin.templates.calendar.CalendarUtils.java
License:Apache License
@NonNull private static List<CalendarItem> fillCalendarTillCurrentDate(@NonNull final DateTime cleanStartDate, @NonNull final DateTime startDate) { DateTime temp = startDate; final List<CalendarItem> calendarItems = new ArrayList<>(); int shift = 0; final int firstDate = temp.getDayOfMonth() - 1; //?? - 1 ? // add first month header calendarItems.add(new CalendarHeaderItem(temp.getYear(), temp.get(DateTimeFieldType.monthOfYear()) - 1, shift, shift)); // is Month starts from 1 or 0 ? temp = temp.withDayOfMonth(1);/* w ww . j a va 2s. c o m*/ shift += 1; final int firstDayInTheWeek = temp.getDayOfWeek() - 1; // check if first day is Monday. If not - add empty items. Otherwise do nothing if (firstDayInTheWeek != 0) { calendarItems.add(new CalendarEmptyItem(shift, shift + firstDayInTheWeek - 1)); } shift += firstDayInTheWeek; // add range with days before today calendarItems.add(new CalendarDayItem(temp.getMillis(), 1, shift, shift + firstDate - 1, ComparingToToday.BEFORE_TODAY)); shift += firstDate; // add today item temp = cleanStartDate; calendarItems .add(new CalendarDayItem(temp.getMillis(), firstDate + 1, shift, shift, ComparingToToday.TODAY)); //add empty items and header if current day the last day in the month if (temp.getDayOfMonth() == temp.dayOfMonth().getMaximumValue()) { addItemsIfCurrentDayTheLastDayInTheMonth(startDate, calendarItems); } return calendarItems; }
From source file:singlejartest.Explorer30or5MinRepeat.java
License:Open Source License
protected static DateTime calcEndBar() { // During weekend set end bar to last trading bar of previous Friday DateTime timeStamp = new DateTime(), roundedEnd = new DateTime(timeStamp.getYear(), timeStamp.getMonthOfYear(), timeStamp.getDayOfMonth(), timeStamp.getHourOfDay(), timeStamp.getMinuteOfHour() % 5 == 0 ? timeStamp.getMinuteOfHour() : (timeStamp.getMinuteOfHour() / 5) * 5, 0, 0), result = new DateTime(roundedEnd); if ((roundedEnd.getDayOfWeek() == DateTimeConstants.FRIDAY && roundedEnd.getHourOfDay() > 22) || roundedEnd.getDayOfWeek() == DateTimeConstants.SATURDAY || (roundedEnd.getDayOfWeek() == DateTimeConstants.SUNDAY && roundedEnd.getHourOfDay() < 23)) { if (roundedEnd.getDayOfWeek() == DateTimeConstants.FRIDAY) result = new DateTime(roundedEnd.getYear(), roundedEnd.getMonthOfYear(), roundedEnd.getDayOfMonth(), 22, 30, 0, 0);/*from ww w.ja v a2 s . c o m*/ else if (roundedEnd.getDayOfWeek() == DateTimeConstants.SATURDAY) { DateTime friday = new DateTime(roundedEnd.minusDays(1)); result = new DateTime(friday.getYear(), friday.getMonthOfYear(), friday.getDayOfMonth(), 22, 30, 0, 0); } else if (roundedEnd.getDayOfWeek() == DateTimeConstants.SUNDAY && roundedEnd.getHourOfDay() < 23) { DateTime friday = new DateTime(roundedEnd.minusDays(2)); result = new DateTime(friday.getYear(), friday.getMonthOfYear(), friday.getDayOfMonth(), 22, 30, 0, 0); } } return result; }
From source file:singlejartest.LastNightExplorer.java
License:Open Source License
/** * returns last occurred 6 am CET bar//from www. j ava2 s . c o m * * @param daysBack * @return */ protected static DateTime calcEndBar(int daysBack) { // During weekend set end bar to last trading bar of previous Friday DateTime timeStamp = new DateTime().minusDays(daysBack), roundedEnd = new DateTime(timeStamp.getYear(), timeStamp.getMonthOfYear(), timeStamp.getDayOfMonth(), 6, 0, 0, 0), result = new DateTime(timeStamp.getHourOfDay() < 6 ? roundedEnd.minusDays(1) : roundedEnd); if (roundedEnd.getDayOfWeek() == DateTimeConstants.SATURDAY || roundedEnd.getDayOfWeek() == DateTimeConstants.SUNDAY) { if (roundedEnd.getDayOfWeek() == DateTimeConstants.SATURDAY) { DateTime friday = new DateTime(roundedEnd.minusDays(1)); result = new DateTime(friday); } else if (roundedEnd.getDayOfWeek() == DateTimeConstants.SUNDAY && roundedEnd.getHourOfDay() < 23) { DateTime friday = new DateTime(roundedEnd.minusDays(2)); result = new DateTime(friday); } } return result; }
From source file:singlejartest.Strategy30MinRepeat.java
License:Open Source License
protected static DateTime calcEndBar() { // During weekend set end bar to last trading bar of previous Friday DateTime timeStamp = new DateTime(), roundedEnd = new DateTime(timeStamp.getYear(), timeStamp.getMonthOfYear(), timeStamp.getDayOfMonth(), timeStamp.getHourOfDay(), timeStamp.getMinuteOfHour() < 30 ? 0 : 30, 0, 0), result = new DateTime(roundedEnd); if ((roundedEnd.getDayOfWeek() == DateTimeConstants.FRIDAY && roundedEnd.getHourOfDay() > 22) || roundedEnd.getDayOfWeek() == DateTimeConstants.SATURDAY || (roundedEnd.getDayOfWeek() == DateTimeConstants.SUNDAY && roundedEnd.getHourOfDay() < 23)) { if (roundedEnd.getDayOfWeek() == DateTimeConstants.FRIDAY) result = new DateTime(roundedEnd.getYear(), roundedEnd.getMonthOfYear(), roundedEnd.getDayOfMonth(), 22, 30, 0, 0);//from w w w. j a va 2 s. c o m else if (roundedEnd.getDayOfWeek() == DateTimeConstants.SATURDAY) { DateTime friday = new DateTime(roundedEnd.minusDays(1)); result = new DateTime(friday.getYear(), friday.getMonthOfYear(), friday.getDayOfMonth(), 22, 30, 0, 0); } else if (roundedEnd.getDayOfWeek() == DateTimeConstants.SUNDAY && roundedEnd.getHourOfDay() < 23) { DateTime friday = new DateTime(roundedEnd.minusDays(2)); result = new DateTime(friday.getYear(), friday.getMonthOfYear(), friday.getDayOfMonth(), 22, 30, 0, 0); } } return result; }
From source file:stroom.pipeline.server.writer.PathCreator.java
License:Apache License
public static String replaceTimeVars(String path) { // Replace some of the path elements with system variables. final DateTime dateTime = new DateTime(DateTimeZone.UTC); path = replace(path, "year", dateTime.getYear(), 4); path = replace(path, "month", dateTime.getMonthOfYear(), 2); path = replace(path, "day", dateTime.getDayOfMonth(), 2); path = replace(path, "hour", dateTime.getHourOfDay(), 2); path = replace(path, "minute", dateTime.getMinuteOfHour(), 2); path = replace(path, "second", dateTime.getSecondOfMinute(), 2); path = replace(path, "millis", dateTime.getMillisOfSecond(), 3); path = replace(path, "ms", dateTime.getMillis(), 0); return path;//from w w w . j a va 2s .c o m }
From source file:swrbPointCase.ShortwaveRadiationBalancePointCase.java
License:GNU General Public License
/** * Compute the correction factor related to Earths orbit eccentricity. * * @param date is the current date//from w ww . ja v a 2 s .c om * @return the double value of E0 */ private double computeE0(DateTime date) { // k is the day angle in radiant double k = 2 * Math.PI * (date.getDayOfMonth() - 1.0) / 365.0; return 1.00011 + 0.034221 * Math.cos(k) + 0.00128 * Math.sin(k) + 0.000719 * Math.cos(2 * k) + 0.000077 * Math.sin(2 * k); }
From source file:teamattendance.TeamAttendance.java
public Date[] getDates() { Scanner sc = new Scanner(System.in); System.out.print("Month/Day/Year: "); String date = sc.nextLine();/*w w w . jav a2 s .c o m*/ String[] splitDate; int[] theDate = new int[3]; // Error checking if (date.compareToIgnoreCase("today") == 0) { DateTime today = new DateTime(); theDate[0] = today.getMonthOfYear(); theDate[1] = today.getDayOfMonth(); theDate[2] = today.getYear(); } else if (date.compareToIgnoreCase("yesterday") == 0) { DateTime today = new DateTime(); theDate[0] = today.getMonthOfYear(); theDate[1] = today.getDayOfMonth() - 1; theDate[2] = today.getYear(); } else { splitDate = date.split("/"); if (splitDate[2].length() == 2) splitDate[2] = "20" + splitDate[2]; theDate[2] = Integer.parseInt(splitDate[2]); theDate[1] = Integer.parseInt(splitDate[0]); theDate[0] = Integer.parseInt(splitDate[1]); } Date[] startEnd = { new Date(theDate[2] - 1900, theDate[0] - 1, theDate[1], 17, 0), new Date(theDate[2] - 1900, theDate[0] - 1, theDate[1], 22, 0) }; return startEnd; }