List of usage examples for org.joda.time DateTime withFieldAdded
public DateTime withFieldAdded(DurationFieldType fieldType, int amount)
From source file:cl.usach.managedbeans.GraficoManagedBean.java
public Map<String, Number> inicializarMAP(Date fechai, Date fechaf) { Map<String, Number> valores = new HashMap<>(); try {//from w w w. j ava 2 s .co m fechai = formatter.parse(formatter.format(fechai)); fechaf = formatter.parse(formatter.format(fechaf)); DateTime datei = new DateTime(fechai); DateTime datef = new DateTime(fechaf); int dias = Days.daysBetween(datei, datef).getDays(); for (int i = 0; i <= dias; i++) { DateTime d = datei.withFieldAdded(DurationFieldType.days(), i); valores.put(formatter.format(d.toDate()), 0); } return valores; } catch (ParseException ex) { Logger.getLogger(GraficoManagedBean.class.getName()).log(Level.SEVERE, null, ex); return null; } }
From source file:com.facebook.util.TimeIntervalType.java
License:Apache License
/** * Gets the start instant given the event instant, interval length * and the time zone for this interval type. * /*from w w w.j a va2s. c om*/ * @param instant the event time instant. * @param length the interval length * * @return the start instant of the interval of given length that contains * the supplied time instant in the supplied time zone */ public DateTime getTimeIntervalStart(DateTime instant, long length) { validateValue(instant.getZone(), length); // Get the time in the specified timezone DateTime periodStart = instant; // Clear all the fields for this intervalType and its subtypes TimeIntervalType timeIntervalType = this; while (timeIntervalType != null) { periodStart = timeIntervalType.clearField(periodStart); timeIntervalType = timeIntervalType.subType; } // figure out the which time interval does the instant lie in Period period = new Period(periodStart, instant, periodType); DurationField durationField = fieldType.getField(instant.getChronology()).getDurationField(); int diff = period.get(durationField.getType()); long startDelta = (diff / length) * length; return periodStart.withFieldAdded(durationField.getType(), FieldUtils.safeToInt(startDelta)); }
From source file:edu.cmu.cs.lti.discoursedb.io.wikipedia.util.RevisionUtils.java
License:Open Source License
/** * Returns the revision of an article at a particular age * // ww w . j a v a 2s.c o m * @param articleId id of the article * @param creationTS explicitly defines the creation TimeStamp from where to count (e.g. if we want to retrieve the revision of the TalkPage based on the age of the article Page) * @param ageInDays age in days * @param revApi revisionApi object * @return the revision object, if it exists. null, else */ public static Revision getRevisionForAge(int articleId, Timestamp creationTS, int ageInDays, RevisionApi revApi) throws WikiApiException { DateTime creation = new DateTime(creationTS); DateTime version = creation.withFieldAdded(DurationFieldType.days(), ageInDays); for (Timestamp curTS : revApi.getRevisionTimestamps(articleId)) { DateTime curDT = new DateTime(curTS); if (curDT.isEqual(version) || curDT.isAfter(version)) { return revApi.getRevision(articleId, curTS); } } return null; }
From source file:eu.eidas.auth.engine.metadata.MetadataGenerator.java
License:EUPL
private DateTime getExpireDate() { DateTime expiryDate = DateTime.now(); expiryDate = expiryDate.withFieldAdded(DurationFieldType.seconds(), (int) (getConfigParams().getValidityDuration())); return expiryDate; }
From source file:net.cbtltd.rest.nextpax.A_Handler.java
License:Open Source License
private void createSchedule(SortedSet<DateTime> availableDates, Product product, Date version, SqlSession sqlSession) {// w w w . j a va 2 s . c o m DateTime currentDate = new DateTime(version).withTime(0, 0, 0, 0); // create reservation if current date is less than the first date in the available dates set DateTime firstAvailableDate = availableDates.first(); int daysBetween = Days.daysBetween(currentDate, availableDates.first()).getDays(); if (daysBetween > 1) { PartnerService.createSchedule(sqlSession, product, currentDate.toDate(), firstAvailableDate.withFieldAdded(DurationFieldType.days(), -1).toDate(), version); } DateTime fromDate = firstAvailableDate; boolean first = true; for (DateTime toDate : availableDates) { if (first) { first = false; continue; } daysBetween = Days.daysBetween(fromDate, toDate).getDays(); if (daysBetween > 1 && toDate.isAfterNow()) { PartnerService.createSchedule(sqlSession, product, fromDate.withFieldAdded(DurationFieldType.days(), 1).toDate(), toDate.withFieldAdded(DurationFieldType.days(), -1).toDate(), version); } fromDate = toDate; } }
From source file:net.cbtltd.rest.yandex.A_Handler.java
License:Open Source License
private void createSchedule(SortedSet<DateTime> availableDates, Product product, Date version, SqlSession sqlSession) {/*from w w w. j av a 2 s . c o m*/ DateTime currentDate = new DateTime(version).withTime(0, 0, 0, 0); // create reservation if current date is less than the first date in the available dates set DateTime firstAvailableDate = availableDates.first(); System.out.println("firstAvailableDate = " + firstAvailableDate); int daysBetween = Days.daysBetween(currentDate, availableDates.first()).getDays(); System.out.println("createSchedule daysBetween: " + daysBetween); System.out.println("daysBetween = " + currentDate + ", " + availableDates.first()); if (daysBetween > 1) { PartnerService.createSchedule(sqlSession, product, currentDate.toDate(), firstAvailableDate.withFieldAdded(DurationFieldType.days(), -1).toDate(), version); } DateTime fromDate = firstAvailableDate; boolean first = true; System.out.println("availableDates size = " + availableDates.size()); for (DateTime toDate : availableDates) { if (first) { first = false; continue; } daysBetween = Days.daysBetween(fromDate, toDate).getDays(); if (daysBetween > 1 && toDate.isAfterNow()) { System.out.println("createSchedule availableDates daysBetween: " + daysBetween); PartnerService.createSchedule(sqlSession, product, fromDate.withFieldAdded(DurationFieldType.days(), 1).toDate(), toDate.withFieldAdded(DurationFieldType.days(), -1).toDate(), version); } fromDate = toDate; } }
From source file:net.sourceforge.fenixedu.domain.student.WeeklyWorkLoad.java
License:Open Source License
public Interval getInterval() { final DateTime beginningOfSemester = new DateTime(getAttends().getBegginingOfLessonPeriod()); final DateTime firstMonday = beginningOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1); final DateTime start = firstMonday.withFieldAdded(DurationFieldType.weeks(), getWeekOffset().intValue()); final DateTime end = start.plusWeeks(1); return new Interval(start, end); }
From source file:org.opentestsystem.delivery.testadmin.service.impl.ScheduleReportServiceImpl.java
License:Open Source License
public List<TestAdminReport> buildScheduledReport(String institutionId, DateTime startDate, DateTime endDate) { List<Schedule> scheduledList = scheduleRepository.findScheduleByStartDateAndEndDate(institutionId, startDate, endDate);/*from w w w . j a v a2s. co m*/ List<ScheduledDay> allScheduleDays = new ArrayList<ScheduledDay>(); for (Schedule schedule : scheduledList) { allScheduleDays.addAll(schedule.getScheduledDays()); } // Now Filter the Scheduled based on the given Date int days = Days.daysBetween(startDate, endDate).getDays(); List<DateTime> rangeOfdates = new ArrayList<DateTime>(); if (days == 0) { rangeOfdates.add(startDate); } else { for (int i = 0; i <= days; i++) { DateTime d = startDate.withFieldAdded(DurationFieldType.days(), i); rangeOfdates.add(d); } } return populateScheduleReport(allScheduleDays, rangeOfdates, institutionId); }