List of usage examples for org.joda.time DateTime getDayOfWeek
public int getDayOfWeek()
From source file:org.apache.phoenix.expression.function.DayOfWeekFunction.java
License:Apache License
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { Expression arg = getChildren().get(0); if (!arg.evaluate(tuple, ptr)) { return false; }//from www . ja v a2 s. c o m 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; }
From source file:org.bensteele.jirrigate.Irrigator.java
License:Open Source License
/** * Returns the time and date the next irrigation is due based on the watering_days and * watering_start_time. It does not take into account whether or not any of the {@link Controller} * are active./*from w w w .ja va 2 s . c o m*/ * * @return The time and date of the next irrigation for any controller under this irrigator's * control. */ protected DateTime nextIrrigationAt() { DateTime dt = new DateTime(); for (int i = 0; i < 7; i++) { for (final int dayOfWeek : wateringDays) { if (dayOfWeek == (dt.getDayOfWeek())) { // If it's the first run then we may match the same day we are currently on, in this case // we need to check that we don't report a time in the past. Validate that the hour and // minute right now are not past the scheduled watering time. If it's not the first run // then it's ok to let through. if (i != 0 || (i == 0 && dt.toLocalTime().isBefore(wateringStartTime))) { // Reset the hour to 0 and increment until we match the watering hour. dt = dt.withHourOfDay(0); while (dt.getHourOfDay() < wateringStartTime.getHourOfDay()) { dt = dt.plusHours(1); } // Reset the minute to 0 and increment until we match the watering minute. dt = dt.withMinuteOfHour(0); while (dt.getMinuteOfHour() < wateringStartTime.getMinuteOfHour()) { dt = dt.plusMinutes(1); } return dt; } } } dt = dt.plusDays(1); } return null; }
From source file:org.efaps.esjp.common.uitable.MultiPrint_Base.java
License:Apache License
/** * @param _field Field the date is wanted for * @return datetime array// w ww. ja v a 2 s .co m * @throws EFapsException on error */ protected Object[] getFilter(final Field _field) throws EFapsException { Object[] ret = null; final String filter = _field.getFilter().getDefaultValue(); if (filter != null) { final String[] parts = filter.split(":"); final String range = parts[0]; final int fromSub = parts.length > 1 ? Integer.parseInt(parts[1]) : 0; final int rangeCount = parts.length > 2 ? Integer.parseInt(parts[2]) : 1; DateTime dateFrom = new DateTime(); DateTime dateTo = new DateTime(); if (range != null) { final FilterDefault def = FilterDefault.valueOf(range.toUpperCase()); // to get a timezone dependent DateTim DateTime tmp = DateTimeUtil.translateFromUI(new DateTime()).withTimeAtStartOfDay(); switch (def) { case TODAY: dateFrom = tmp.toDateTime().minusDays(fromSub).minusMinutes(1); dateTo = dateFrom.plusDays(rangeCount).plusSeconds(1); ret = new DateTime[] { dateFrom, dateTo }; break; case WEEK: // the first of the current week tmp = tmp.minusDays(tmp.getDayOfWeek() - 1); dateFrom = tmp.minusWeeks(fromSub).minusMinutes(1); dateTo = tmp.plusWeeks(rangeCount); ret = new DateTime[] { dateFrom, dateTo }; break; case MONTH: // the first of the current month tmp = tmp.minusDays(tmp.getDayOfMonth() - 1); // substract the month and a minute before dateFrom = tmp.minusMonths(fromSub).minusMinutes(1); // add the month dateTo = tmp.plusMonths(rangeCount); ret = new DateTime[] { dateFrom, dateTo }; break; case YEAR: tmp = tmp.minusDays(tmp.getDayOfYear() - 1); dateFrom = tmp.minusYears(fromSub).minusMinutes(1); dateTo = tmp.plusYears(rangeCount); ret = new DateTime[] { dateFrom, dateTo }; break; case ALL: ret = new String[] { "*" }; break; case NONE: break; default: ret = new String[] { range + "*" }; break; } } } return ret; }
From source file:org.entcore.feeder.timetable.edt.EDTImporter.java
License:Open Source License
private JsonObject generateCourse(int startCourseWeek, int endCourseWeek, BitSet enabledItems, List<JsonObject> items, JsonObject entity) { final int day = Integer.parseInt(entity.getString("Jour")); final int startPlace = Integer.parseInt(entity.getString("NumeroPlaceDebut")); final int placesNumber = Integer.parseInt(entity.getString("NombrePlaces")); DateTime startDate = startDateWeek1.plusWeeks(startCourseWeek - 1).plusDays(day - 1); DateTime endDate = startDate.plusWeeks(endCourseWeek - startCourseWeek); startDate = startDate.plusSeconds(slots.get(entity.getString("NumeroPlaceDebut")).getStart()); endDate = endDate.plusSeconds(slots.get(String.valueOf((startPlace + placesNumber - 1))).getEnd()); final JsonObject c = new JsonObject().put("structureId", structureId) .put("subjectId", subjects.get(entity.getJsonArray("Matiere").getJsonObject(0).getString(IDENT))) .put("startDate", startDate.toString()).put("endDate", endDate.toString()) .put("dayOfWeek", startDate.getDayOfWeek()); for (int i = 0; i < enabledItems.size(); i++) { if (enabledItems.get(i)) { final JsonObject item = items.get(i); final String ident = item.getString(IDENT); switch (item.getString("itemType")) { case "Professeur": JsonArray teachersArray = c.getJsonArray("teacherIds"); if (teachersArray == null) { teachersArray = new fr.wseduc.webutils.collections.JsonArray(); c.put("teacherIds", teachersArray); }/*from w w w. java 2 s. c o m*/ final String tId = teachers.get(ident); if (isNotEmpty(tId)) { teachersArray.add(tId); } break; case "Classe": JsonArray classesArray = c.getJsonArray("classes"); if (classesArray == null) { classesArray = new fr.wseduc.webutils.collections.JsonArray(); c.put("classes", classesArray); } JsonObject ci = classes.get(ident); if (ci != null) { classesArray.add(ci.getString("className")); } break; case "Groupe": JsonArray groupsArray = c.getJsonArray("groups"); if (groupsArray == null) { groupsArray = new fr.wseduc.webutils.collections.JsonArray(); c.put("groups", groupsArray); } JsonObject g = groups.get(ident); if (g != null) { groupsArray.add(g.getString("Nom")); } break; case "Materiel": JsonArray equipmentsArray = c.getJsonArray("equipmentLabels"); if (equipmentsArray == null) { equipmentsArray = new fr.wseduc.webutils.collections.JsonArray(); c.put("equipmentLabels", equipmentsArray); } final String eId = equipments.get(ident); if (isNotEmpty(eId)) { equipmentsArray.add(eId); } break; case "Salle": JsonArray roomsArray = c.getJsonArray("roomLabels"); if (roomsArray == null) { roomsArray = new fr.wseduc.webutils.collections.JsonArray(); c.put("roomLabels", roomsArray); } final String rId = rooms.get(ident); if (isNotEmpty(rId)) { roomsArray.add(rId); } break; case "Personnel": JsonArray personnelsArray = c.getJsonArray("personnelIds"); if (personnelsArray == null) { personnelsArray = new fr.wseduc.webutils.collections.JsonArray(); c.put("personnelIds", personnelsArray); } final String pId = personnels.get(ident); if (isNotEmpty(pId)) { personnelsArray.add(pId); } break; } } } try { c.put("_id", JsonUtil.checksum(c)); } catch (NoSuchAlgorithmException e) { log.error("Error generating course checksum", e); } return c; }
From source file:org.envirocar.analyse.categories.DEBasedCategory.java
License:Apache License
protected DateTime getLastSunday(int year, int month, int day) { DateTime lastDay = new DateTime(year, month, day, 0, 0, DateTimeZone.UTC); logger.info("lastDay: " + lastDay.toString()); int dow = lastDay.getDayOfWeek(); logger.info("dow: " + dow); if (dow == 7) { return lastDay; } else {/* w ww . j a v a2 s . c om*/ DateTime result = lastDay.minusDays(dow); logger.info("result: " + result.toString()); return result; } }
From source file:org.envirocar.analyse.categories.TimeBasedCategory.java
License:Apache License
public static TimeBasedCategory fromTime(DateTime dt) { int dow = dt.getDayOfWeek(); int hod = dt.getHourOfDay(); String prefix;/* www.j a va 2s.c om*/ if (dow < DateTimeConstants.SATURDAY) { prefix = "WEEKDAY"; } else if (dow == DateTimeConstants.SATURDAY) { prefix = "SATURDAY"; } else if (dow == DateTimeConstants.SUNDAY) { prefix = "SUNDAY"; } else { return NO_CATEGORY; } if (hod >= 6 && hod < 10) { return TimeBasedCategory.valueOf(prefix.concat("_6_10")); } if (hod >= 10 && hod < 15) { return TimeBasedCategory.valueOf(prefix.concat("_10_15")); } if (hod >= 15 && hod < 19) { return TimeBasedCategory.valueOf(prefix.concat("_15_19")); } else { return TimeBasedCategory.valueOf(prefix.concat("_OTHER")); } }
From source file:org.everit.jira.core.impl.TimetrackerComponent.java
License:Apache License
@Override public DateTime firstMissingWorklogsDate(final Set<DateTime> excludeDatesSet, final Set<DateTime> includeDatesSet, final DateTime currentDay) { DateTime scannedDate = currentDay; // one week/* w w w .j a va 2s . com*/ scannedDate = scannedDate.minusDays(DateTimeConverterUtil.DAYS_PER_WEEK); for (int i = 0; i < DateTimeConverterUtil.DAYS_PER_WEEK; i++) { // check excludse - pass if (TimetrackerUtil.containsSetTheSameDay(excludeDatesSet, scannedDate)) { scannedDate = scannedDate.plusDays(1); continue; } // check includes - not check weekend // check weekend - pass if (!TimetrackerUtil.containsSetTheSameDay(includeDatesSet, scannedDate) && ((scannedDate.getDayOfWeek() == DateTimeConstants.SUNDAY) || (scannedDate.getDayOfWeek() == DateTimeConstants.SATURDAY))) { scannedDate = scannedDate.plusDays(1); continue; } // check worklog. if no worklog set result else ++ scanedDate scannedDate = DateTimeConverterUtil.setDateToDayStart(scannedDate); boolean isDateContainsWorklog = TimetrackerUtil.isContainsWorklog(new Date(scannedDate.getMillis())); if (!isDateContainsWorklog) { return scannedDate; } else { scannedDate = scannedDate.plusDays(1); } } // if we find everything all right then return with the current date return scannedDate; }
From source file:org.fenixedu.academic.api.infra.FenixAPICanteen.java
License:Open Source License
public static String get(String daySearch) { String locale = I18N.getLocale().toString().replace("_", "-"); if (canteenInfo == null || canteenInfo.isJsonNull() || oldInformation()) { String canteenUrl = FenixEduAcademicConfiguration.getConfiguration().getFenixApiCanteenUrl(); try {//ww w. j a v a2 s . co m Response response = HTTP_CLIENT.target(canteenUrl).request(MediaType.APPLICATION_JSON) .header("Authorization", getServiceAuth()).get(); if (response.getStatus() == 200) { JsonParser parser = new JsonParser(); canteenInfo = (JsonObject) parser.parse(response.readEntity(String.class)); day = new DateTime(); } else { return new JsonObject().toString(); } } catch (ProcessingException e) { e.printStackTrace(); return new JsonObject().toString(); } } JsonArray jsonArrayWithLang = canteenInfo.getAsJsonArray(locale); DateTime dayToCompareStart; DateTime dayToCompareEnd; DateTime dateTime = DateTime.parse(daySearch, DateTimeFormat.forPattern(datePattern)); int dayOfWeek = dateTime.getDayOfWeek(); if (dayOfWeek != 7) { dayToCompareStart = dateTime.minusDays(dayOfWeek); dayToCompareEnd = dateTime.plusDays(7 - dayOfWeek); } else { dayToCompareStart = dateTime; dayToCompareEnd = dateTime.plusDays(7); } JsonArray jsonResult = new JsonArray(); for (JsonElement jObj : jsonArrayWithLang) { DateTime dateToCompare = DateTime.parse(((JsonObject) jObj).get("day").getAsString(), DateTimeFormat.forPattern(datePattern)); if (dateToCompare.isAfter(dayToCompareStart) && dateToCompare.isBefore(dayToCompareEnd)) { jsonResult.add(jObj); } } Gson gson = new GsonBuilder().setPrettyPrinting().create(); return gson.toJson(jsonResult); }
From source file:org.fenixedu.academic.api.infra.FenixAPIFromExternalServer.java
License:Open Source License
public static String getCanteen(String daySearch) { getInformation();/*w ww.java2 s.c o m*/ String lang = I18N.getLocale().toLanguageTag(); if (!canteenInfo.has(lang)) { return empty.toString(); } JsonArray jsonArrayWithLang = canteenInfo.getAsJsonObject().getAsJsonArray(lang); DateTime dayToCompareStart; DateTime dayToCompareEnd; DateTime dateTime = DateTime.parse(daySearch, DateTimeFormat.forPattern(datePattern)); int dayOfWeek = dateTime.getDayOfWeek(); if (dayOfWeek != 7) { dayToCompareStart = dateTime.minusDays(dayOfWeek); dayToCompareEnd = dateTime.plusDays(7 - dayOfWeek); } else { dayToCompareStart = dateTime; dayToCompareEnd = dateTime.plusDays(7); } Interval validInterval = new Interval(dayToCompareStart, dayToCompareEnd); JsonArray jsonResult = new JsonArray(); for (JsonElement jObj : jsonArrayWithLang) { DateTime dateToCompare = DateTime.parse(((JsonObject) jObj).get("day").getAsString(), DateTimeFormat.forPattern(datePattern)); if (validInterval.contains(dateToCompare)) { jsonResult.add(jObj); } } return gson.toJson(jsonResult); }
From source file:org.fenixedu.spaces.domain.occupation.config.ExplicitConfigWithSettings.java
License:Open Source License
private static int getNthDayOfWeek(DateTime when) { DateTime checkpoint = when; int whenDayOfWeek = checkpoint.getDayOfWeek(); int month = checkpoint.getMonthOfYear(); checkpoint = checkpoint.withDayOfMonth(1); checkpoint = checkpoint.withDayOfWeek(whenDayOfWeek); checkpoint = checkpoint.plusWeeks(month - checkpoint.getDayOfMonth()); int i = 0;/*from www.ja v a 2s . c o m*/ while (checkpoint.getMonthOfYear() == month && !checkpoint.isEqual(when)) { checkpoint = checkpoint.plusWeeks(1); i++; } return i; }