Java Code Examples for org.joda.time.DateTime#getDayOfWeek()
The following examples show how to use
org.joda.time.DateTime#getDayOfWeek() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DayOfWeekFunction.java From phoenix with Apache License 2.0 | 6 votes |
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { Expression arg = getChildren().get(0); if (!arg.evaluate(tuple,ptr)) { return false; } if (ptr.getLength() == 0) { return true; } long dateTime = inputCodec.decodeLong(ptr, arg.getSortOrder()); DateTime jodaDT = new DateTime(dateTime); int day = jodaDT.getDayOfWeek(); PDataType returnDataType = getDataType(); byte[] byteValue = new byte[returnDataType.getByteSize()]; returnDataType.getCodec().encodeInt(day, byteValue, 0); ptr.set(byteValue); return true; }
Example 2
Source File: InstanceCooltimeData.java From aion-germany with GNU General Public License v3.0 | 6 votes |
private long getUpdateHours(String[] days, int hour) { DateTime now = DateTime.now(); DateTime repeatDate = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), hour, 0, 0); int curentDay = now.getDayOfWeek(); for (String name : days) { int day = getDay(name); if (day < curentDay) { continue; } if (day == curentDay) { if (now.isBefore(repeatDate)) { return repeatDate.getMillis(); } } else { repeatDate = repeatDate.plusDays(day - curentDay); return repeatDate.getMillis(); } } return repeatDate.plusDays((7 - curentDay) + getDay(days[0])).getMillis(); }
Example 3
Source File: PersianCalendar.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public int isoWeekday( DateTimeUnit dateTimeUnit ) { DateTime dateTime = toIso( dateTimeUnit ) .toJodaDateTime( ISOChronology.getInstance( DateTimeZone.getDefault() ) ); return dateTime.getDayOfWeek(); }
Example 4
Source File: TimeRestrictedAccessPolicy.java From apiman with Apache License 2.0 | 5 votes |
/** * Returns true if the given time matches the day-of-week restrictions specified * by the included filter/rule. * @param currentTime * @param filter */ private boolean matchesDay(DateTime currentTime, TimeRestrictedAccess filter) { Integer dayStart = filter.getDayStart(); Integer dayEnd = filter.getDayEnd(); int dayNow = currentTime.getDayOfWeek(); if (dayStart >= dayEnd) { return dayNow >= dayStart && dayNow <= dayEnd; } else { return dayNow <= dayEnd && dayNow >= dayStart; } }
Example 5
Source File: StatisticsXmlReportGenerator.java From megatron-java with Apache License 2.0 | 5 votes |
private DateTime startDateTime(int noOfWeeks) { // find first monday DateTime result = new DateTime(); while (true) { if (result.getDayOfWeek() == DateTimeConstants.MONDAY) { break; } result = result.minusDays(1); } return result.minusDays(7*noOfWeeks); }
Example 6
Source File: DateTimeFunctions.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * Returns a date a number of workdays away. Saturday and Sundays are not considered working days. */ @Function("WORKDAY") @FunctionParameters({ @FunctionParameter("dateObject"), @FunctionParameter("workdays")}) public Date WORKDAY(Object dateObject, Integer workdays){ Date convertedDate = convertDateObject(dateObject); if(convertedDate==null){ logCannotConvertToDate(); return null; } else{ boolean lookBack = workdays<0; DateTime cursorDT=new DateTime(convertedDate); int remainingDays=Math.abs(workdays); while(remainingDays>0){ int dayOfWeek = cursorDT.getDayOfWeek(); if(!(dayOfWeek==DateTimeConstants.SATURDAY || dayOfWeek==DateTimeConstants.SUNDAY)){ // Decrement remaining days only when it is not Saturday or Sunday remainingDays--; } if(!lookBack) { cursorDT= dayOfWeek==DateTimeConstants.FRIDAY?cursorDT.plusDays(3):cursorDT.plusDays(1); } else { cursorDT= dayOfWeek==DateTimeConstants.MONDAY?cursorDT.minusDays(3):cursorDT.minusDays(1); } } return cursorDT.toDate(); } }
Example 7
Source File: TimePeriod.java From megatron-java with Apache License 2.0 | 5 votes |
/** * Returns date for monday in specified week. * * @param weekStr full week string, e.g. "2010-01" (which will return 2010-01-04). */ private DateTime parseIsoWeek(String weekStr) throws Exception { DateTime result = null; // Split year and week String[] headTail = StringUtil.splitHeadTail(weekStr, "-", false); if ((headTail == null) || StringUtil.isNullOrEmpty(headTail[0]) || StringUtil.isNullOrEmpty(headTail[1]) || (headTail[0].length() != 4)) { throw new Exception("Invalid week string: " + weekStr); } // Get monday of week 1. // The first week of a year is the one that includes the first Thursday of the year. // http://www.fourmilab.ch/documents/calendar/ // http://joda-time.sourceforge.net/cal_iso.html String day1InYear = headTail[0] + "-01-01"; DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd"); result = fmt.parseDateTime(day1InYear); if (result.getDayOfWeek() <= DateTimeConstants.THURSDAY) { while (result.getDayOfWeek() != DateTimeConstants.MONDAY) { result = result.minusDays(1); } } else { while (result.getDayOfWeek() != DateTimeConstants.MONDAY) { result = result.plusDays(1); } } // Add week number int week = Integer.parseInt(headTail[1]); if ((week < 1) || (week > 53)) { throw new Exception("Invalid week string: " + weekStr); } result = result.plusDays(7*(week-1)); return result; }
Example 8
Source File: QuestService.java From aion-germany with GNU General Public License v3.0 | 5 votes |
private static Timestamp countNextRepeatTime(Player player, QuestTemplate template) { int questCooltime = template.getQuestCoolTime(); DateTime now = DateTime.now(); DateTime repeatDate = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 9, 0, 0); if (template.isDaily()) { if (now.isAfter(repeatDate)) { repeatDate = repeatDate.plusHours(24); } PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1400855, "9")); } else if (template.getQuestCoolTime() > 0) { repeatDate = repeatDate.plusSeconds(template.getQuestCoolTime()); // This quest can be re-attempted in %DURATIONDAY0s. PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1402676, +questCooltime)); } else { int daysToAdd = 7; int startDay = 7; for (QuestRepeatCycle weekDay : template.getRepeatCycle()) { int diff = weekDay.getDay() - repeatDate.getDayOfWeek(); if (diff > 0 && diff < daysToAdd) { daysToAdd = diff; } if (startDay > weekDay.getDay()) { startDay = weekDay.getDay(); } } if (startDay == daysToAdd) { daysToAdd = 7; } else if (daysToAdd == 7 && startDay < 7) { daysToAdd = 7 - repeatDate.getDayOfWeek() + startDay; } repeatDate = repeatDate.plusDays(daysToAdd); PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1400857, new DescriptionId(1800667), "9")); } return new Timestamp(repeatDate.getMillis()); }
Example 9
Source File: GanttDiagram.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
private void calculateFirstAndLastInstantInWeeklyMode(YearMonthDay begin) { if (begin == null) { throw new IllegalArgumentException(); } DateTime beginDateTime = begin.toDateTimeAtMidnight(); beginDateTime = (beginDateTime.getDayOfWeek() != 1) ? beginDateTime.withDayOfWeek(1) : beginDateTime; setFirstInstant(beginDateTime); setLastInstant(beginDateTime.plusDays(6)); }
Example 10
Source File: ChronologyBasedCalendar.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public int isoWeekday( DateTimeUnit dateTimeUnit ) { DateTime dateTime = dateTimeUnit.toJodaDateTime( chronology ); dateTime = dateTime.withChronology( ISOChronology.getInstance( DateTimeZone.getDefault() ) ); return dateTime.getDayOfWeek(); }
Example 11
Source File: PvPArenaService.java From aion-germany with GNU General Public License v3.0 | 5 votes |
private static boolean isHarmonyArenaAvailable() { DateTime now = DateTime.now(); int hour = now.getHourOfDay(); int day = now.getDayOfWeek(); if (day == 6) { return hour >= 10 || hour == 1 || hour == 2; } else if (day == 7) { return hour == 0 || hour == 1 || hour >= 10; } else { return (hour >= 10 && hour < 14) || (hour >= 18 && hour <= 23); } }
Example 12
Source File: EventSpaceOccupation.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
protected DateTime getInstant(boolean firstInstant, YearMonthDay begin, final YearMonthDay end, final HourMinuteSecond beginTime, final HourMinuteSecond endTime, final FrequencyType frequency, final DiaSemana diaSemana, final Boolean dailyFrequencyMarkSaturday, final Boolean dailyFrequencyMarkSunday) { DateTime instantResult = null; begin = getBeginDateInSpecificWeekDay(diaSemana, begin); if (frequency == null) { if (!begin.isAfter(end)) { if (firstInstant) { return begin.toDateTime(new TimeOfDay(beginTime.getHour(), beginTime.getMinuteOfHour(), 0, 0)); } else { return end.toDateTime(new TimeOfDay(endTime.getHour(), endTime.getMinuteOfHour(), 0, 0)); } } } else { int numberOfDaysToSum = frequency.getNumberOfDays(); while (true) { if (begin.isAfter(end)) { break; } DateTime intervalEnd = begin.toDateTime(new TimeOfDay(endTime.getHour(), endTime.getMinuteOfHour(), 0, 0)); if (!frequency.equals(FrequencyType.DAILY) || ((dailyFrequencyMarkSaturday || intervalEnd.getDayOfWeek() != SATURDAY_IN_JODA_TIME) && (dailyFrequencyMarkSunday || intervalEnd .getDayOfWeek() != SUNDAY_IN_JODA_TIME))) { if (firstInstant) { return begin.toDateTime(new TimeOfDay(beginTime.getHour(), beginTime.getMinuteOfHour(), 0, 0)); } else { instantResult = intervalEnd; } } begin = begin.plusDays(numberOfDaysToSum); } } return instantResult; }
Example 13
Source File: CodeRedNurserAI2.java From aion-germany with GNU General Public License v3.0 | 5 votes |
@Override protected void handleSpawned() { DateTime now = DateTime.now(); int currentDay = now.getDayOfWeek(); switch (getNpcId()) { case 831435: // Jorpine (MON-THU) case 831436: // Yennu (MON-THU) case 831441: // Hylian (MON-THU) case 831442: {// Rordah (MON-THU) if (currentDay >= 1 && currentDay <= 4) { super.handleSpawned(); } else if (!isAlreadyDead()) { getOwner().getController().onDelete(); } break; } case 831437: // Dalloren (FRI-SAT) case 831518: // Dalliea (FRI-SAT) case 831443: // Mazka (FRI-SAT) case 831524: { // Deshna (FRI-SAT) if (currentDay >= 5 && currentDay <= 7) { super.handleSpawned(); } else if (!isAlreadyDead()) { getOwner().getController().onDelete(); } break; } } }
Example 14
Source File: SnakeColorsAI2.java From aion-germany with GNU General Public License v3.0 | 5 votes |
@Override protected void handleSpawned() { DateTime now = DateTime.now(); int currentDay = now.getDayOfWeek(); switch (getNpcId()) { case 832975: case 832964: { if (currentDay >= 1 && currentDay <= 4) { super.handleSpawned(); } else if (!isAlreadyDead()) { getOwner().getController().onDelete(); } break; } case 832974: case 832963: { if (currentDay >= 5 && currentDay <= 7) { super.handleSpawned(); } else if (!isAlreadyDead()) { getOwner().getController().onDelete(); } break; } } }
Example 15
Source File: PvPArenaService.java From aion-germany with GNU General Public License v3.0 | 4 votes |
private static boolean isGloryArenaAvailable() { DateTime now = DateTime.now(); int hour = now.getHourOfDay(); int day = now.getDayOfWeek(); return (day == 6 || day == 7) && hour >= 20 && hour < 22; }
Example 16
Source File: DiaSemana.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 4 votes |
public static int getDiaSemana(YearMonthDay date) { DateTime dateTime = date.toDateTimeAtMidnight(); return dateTime.getDayOfWeek() == 7 ? 1 : dateTime.getDayOfWeek() + 1; }
Example 17
Source File: DateTimeBrowser.java From astor with GNU General Public License v2.0 | 4 votes |
Object[][] genCalcdValues() { Object[][] retValues = null; /* * Create an array of Objects that will contain * other arrays of Objects. (This is the 'column' * array). */ ArrayList fileStrings = lddFile.getFileStrings(); ArrayList dtObjects = lddFile.getDtObjects(); int numRows = fileStrings.size(); retValues = new Object[numRows][]; int numCols = colNames.length; // System.err.println("NumCols : " + numCols); /* * Prime the array of arrays of Objects, allocating a new * secondary array for each of the primary array's * elements. */ for (int nextStrNum = 0; nextStrNum < fileStrings.size(); ++ nextStrNum) { retValues[nextStrNum] = new Object[numCols]; // get the 'col' array //**** //* This needs to be sync'd with the colNames array. //**** // Current row, 1st column int column = 0; // working row value String fileString = (String)fileStrings.get(nextStrNum); retValues[nextStrNum][column++] = fileString; // Current row, 2nd column DateTime adt = (DateTime)dtObjects.get(nextStrNum); String adtStr = adt.toString(); retValues[nextStrNum][column++] = adtStr; // Current row, other columns. // Order here must match that specified in the colNames // array. retValues[nextStrNum][column++] = new Integer( adt.getMillisOfSecond() ); retValues[nextStrNum][column++] = new Integer( adt.getSecondOfMinute() ); retValues[nextStrNum][column++] = new Integer( adt.getMinuteOfHour() ); retValues[nextStrNum][column++] = new Integer( adt.getHourOfDay() ); retValues[nextStrNum][column++] = new Integer( adt.getDayOfWeek() ); retValues[nextStrNum][column++] = new Integer( adt.getDayOfMonth() ); retValues[nextStrNum][column++] = new Integer( adt.getDayOfYear() ); retValues[nextStrNum][column++] = new Integer( adt.getWeekOfWeekyear() ); retValues[nextStrNum][column++] = new Integer( adt.getWeekyear() ); retValues[nextStrNum][column++] = new Integer( adt.getMonthOfYear() ); retValues[nextStrNum][column++] = new Integer( adt.getYear() ); // } // the for if ( debugf ) dumpObjs( retValues, System.err ); return retValues; }
Example 18
Source File: TimeUtils.java From OmniList with GNU Affero General Public License v3.0 | 4 votes |
public static Date nextMonday() { DateTime dateTime = new DateTime(); int week = dateTime.getDayOfWeek(); int offset = week == DateTimeConstants.SUNDAY ? 1 : 8 - week; return dateTime.plusDays(offset).withTimeAtStartOfDay().toDate(); }
Example 19
Source File: NepaliCalendar.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public int isoWeekday( DateTimeUnit dateTimeUnit ) { DateTime dateTime = toIso( dateTimeUnit ).toJodaDateTime( ISOChronology.getInstance( DateTimeZone.getDefault() ) ); return dateTime.getDayOfWeek(); }
Example 20
Source File: TimeUtils.java From OmniList with GNU Affero General Public License v3.0 | 4 votes |
public static Date thisFriday() { DateTime dateTime = new DateTime(); int week = dateTime.getDayOfWeek(); int offset = week == DateTimeConstants.SUNDAY ? 5 : 5 - week; return dateTime.plusDays(offset).withTimeAtStartOfDay().toDate(); }