List of usage examples for org.joda.time Duration getStandardDays
public long getStandardDays()
From source file:dk.dma.arcticweb.service.AppDataServiceBean.java
License:Apache License
private void createSarfaqSchedule() { logger.info("BEFORE SCHEDULE - SARFAQ"); Vessel sarfaq = vesselDao.getVessel(331037000L); DateTime now = DateTime.now(DateTimeZone.UTC); DateTimeConverter converter = DateTimeConverter.getDateTimeConverter(); DateTime firstDeparture = converter.toObject("27-09-2013 21:00"); sarfaq.addVoyageEntry(new Voyage("Nuuk", "64 10.4N", "051 43.5W", null, firstDeparture)); sarfaq.addVoyageEntry(new Voyage("Maniitsoq", "65 24.8N", "052 54.3W", converter.toObject("28-09-2013 07:00"), converter.toObject("28-09-2013 07:30"))); sarfaq.addVoyageEntry(new Voyage("Kangaamiut", "65 49.6N", "053 20.9W", converter.toObject("28-09-2013 10:45"), converter.toObject("28-09-2013 11:00"))); sarfaq.addVoyageEntry(new Voyage("Sisimiut", "66 56.5N", "053 40.5W", converter.toObject("28-09-2013 18:00"), converter.toObject("28-09-2013 21:00"))); sarfaq.addVoyageEntry(new Voyage("Aasiaat", "68 42.6N", "052 53.0W", converter.toObject("29-09-2013 08:00"), converter.toObject("29-09-2013 08:30"))); sarfaq.addVoyageEntry(new Voyage("Ilulissat", "69 13.5N", "051 06.0W", converter.toObject("29-09-2013 13:00"), converter.toObject("29-09-2013 17:00"))); sarfaq.addVoyageEntry(new Voyage("Aasiaat", "68 42.6N", "052 53.0W", converter.toObject("29-09-2013 21:30"), converter.toObject("29-09-2013 22:00"))); sarfaq.addVoyageEntry(new Voyage("Sisimiut", "66 56.5N", "053 40.5W", converter.toObject("30-09-2013 09:00"), converter.toObject("30-09-2013 10:30"))); sarfaq.addVoyageEntry(new Voyage("Kangaamiut", "65 49.6N", "053 20.9W", converter.toObject("30-09-2013 17:30"), converter.toObject("30-09-2013 17:45"))); sarfaq.addVoyageEntry(new Voyage("Maniitsoq", "65 24.8N", "052 54.3W", converter.toObject("30-09-2013 21:30"), converter.toObject("30-09-2013 22:00"))); sarfaq.addVoyageEntry(new Voyage("Nuuk", "64 10.4N", "051 43.5W", converter.toObject("01-10-2013 06:30"), converter.toObject("01-10-2013 09:00"))); sarfaq.addVoyageEntry(new Voyage("Qeqertarsuatsiaat", "63 05.4N", "050 41.0W", converter.toObject("01-10-2013 16:30"), converter.toObject("01-10-2013 16:45"))); sarfaq.addVoyageEntry(new Voyage("Paamiut", "61 59.8N", "049 40.8W", converter.toObject("01-10-2013 23:30"), converter.toObject("02-10-2013 00:00"))); sarfaq.addVoyageEntry(new Voyage("Arsuk", "61 10.5N", "048 27.1W", converter.toObject("02-10-2013 06:45"), converter.toObject("02-10-2013 07:00"))); sarfaq.addVoyageEntry(new Voyage("Qaqortoq", "60 43.1N", "046 02.4W", converter.toObject("02-10-2013 15:30"), converter.toObject("02-10-2013 19:00"))); sarfaq.addVoyageEntry(new Voyage("Narsaq", "60 54.5N", "046 03.0W", converter.toObject("02-10-2013 21:00"), converter.toObject("02-10-2013 21:30"))); sarfaq.addVoyageEntry(new Voyage("Arsuk", "61 10.5N", "048 27.2W", converter.toObject("03-10-2013 06:45"), converter.toObject("03-10-2013 07:00"))); sarfaq.addVoyageEntry(new Voyage("Paamiut", "61 59.8N", "049 40.8W", converter.toObject("03-10-2013 13:30"), converter.toObject("03-10-2013 14:30"))); sarfaq.addVoyageEntry(new Voyage("Qeqertarsuatsiaat", "63 05.4N", "050 41.0W", converter.toObject("03-10-2013 22:30"), converter.toObject("03-10-2013 22:45"))); sarfaq.addVoyageEntry(new Voyage("Nuuk", "64 10.4N", "051 43.5W", converter.toObject("04-10-2013 09:00"), converter.toObject("04-10-2013 11:00"))); // firstDeparture. Duration d = new Duration(firstDeparture, now); int weeks = (int) d.getStandardDays() / 7; logger.debug("Duration: {}, weeks:{}, days: {}", d, weeks, d.getStandardDays()); List<Voyage> schedule = sarfaq.getSchedule(); if (weeks > 0) { for (Voyage v : schedule) { v.setArrival(v.getArrival() == null ? null : v.getArrival().plusWeeks(weeks)); v.setDeparture(v.getDeparture() == null ? null : v.getDeparture().plusWeeks(weeks)); }/* w w w . java2 s . c om*/ } logger.debug("Schedule: {}", schedule); for (Voyage v : schedule) { scheduleDao.saveEntity(v); } em.flush(); }
From source file:models.Milestone.java
License:Apache License
public String until() { Date now = DateUtils.truncate(new Date(), Calendar.DATE); Date dueDate = DateUtils.truncate(this.dueDate, Calendar.DATE); Duration duration = new Duration(new DateTime(now), new DateTime(dueDate)); long days = duration.getStandardDays(); if (days < 0) { return Messages.get("common.time.overday", -days); } else if (days == 0) { return Messages.get("common.time.today"); } else {/*from w ww.j a v a2 s .c o m*/ return Messages.get("common.time.leftday", days); } }
From source file:models.Milestone.java
License:Apache License
public Boolean isOverDueDate() { Duration duration = new Duration(DateTime.now(), new DateTime(dueDate)); long days = duration.getStandardDays(); return (days < 0); }
From source file:org.georchestra.analytics.StatisticsController.java
License:Open Source License
/** * Calculates the appropriate granularity given the begin date and the end date. * * @param beginDate the begin date./*ww w . j a v a 2s.c om*/ * @param endDate the end date. * @return the most relevant GRANULARITY. */ private GRANULARITY guessGranularity(String beginDate, String endDate) { DateTime from = DateTime.parse(beginDate, this.dbOutputFormatter); DateTime to = DateTime.parse(endDate, this.dbOutputFormatter); Duration duration = new Duration(from, to); long numdays = duration.getStandardDays(); if (numdays < 2) { return GRANULARITY.HOUR; } else if (numdays < 90) { return GRANULARITY.DAY; } else if (numdays < 365) { return GRANULARITY.WEEK; } else { return GRANULARITY.MONTH; } }
From source file:org.graylog2.utilities.SearchUtils.java
License:Open Source License
public static Searches.DateHistogramInterval buildInterval(@Nullable final String intervalParam, final TimeRange timeRange) { if (!isNullOrEmpty(intervalParam)) { final String interval = intervalParam.toUpperCase(Locale.ENGLISH); if (!validateInterval(interval)) { throw new IllegalArgumentException("Invalid interval: \"" + interval + "\""); }/*w w w . j a va 2s. c om*/ return Searches.DateHistogramInterval.valueOf(interval); } final Duration duration = Duration.millis(timeRange.getTo().getMillis() - timeRange.getFrom().getMillis()); // This is the same as SearchPage#_determineHistogramResolution() in the UI code if (duration.getStandardHours() < 12) { return Searches.DateHistogramInterval.MINUTE; } else if (duration.getStandardDays() < 3) { return Searches.DateHistogramInterval.HOUR; } else if (duration.getStandardDays() < 30) { return Searches.DateHistogramInterval.DAY; } else if (duration.getStandardDays() < (30 * 2)) { return Searches.DateHistogramInterval.WEEK; } else if (duration.getStandardDays() < (30 * 18)) { return Searches.DateHistogramInterval.MONTH; } else if (duration.getStandardDays() < (365 * 3)) { return Searches.DateHistogramInterval.QUARTER; } else { return Searches.DateHistogramInterval.YEAR; } }
From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.SessionImpl.java
License:Apache License
@Override public String getTimeFancyText(DateTime from, DateTime to) { final String prefix = "Join in "; if (to != null) { Duration d = new Duration(to, from); Period timeUntil = new Period(to.toInstant(), from.toInstant(), PeriodType.dayTime()); long standardDays = d.getStandardDays(); if (standardDays > 0) { PeriodFormatter daysHours = new PeriodFormatterBuilder().appendDays().appendSuffix(" day", " days") .appendSeparator(", and ").appendHours().appendSuffix(" hour", " hours").toFormatter(); return prefix + daysHours.print(timeUntil.normalizedStandard(PeriodType.dayTime())); } else {//from w w w .ja v a 2 s. com PeriodFormatter dafaultFormatter = new PeriodFormatterBuilder().appendHours() .appendSuffix(" hour", " hours").appendSeparator(", and ").appendMinutes() .appendSuffix(" minute", " minutes").toFormatter(); return prefix + dafaultFormatter.print(timeUntil.normalizedStandard(PeriodType.dayTime())); } } else { return null; } }
From source file:org.numenta.nupic.encoders.DateEncoder.java
License:Open Source License
/** * Returns an {@link TDoubleList} containing the sub-field scalar value(s) for * each sub-field of the inputData. To get the associated field names for each of * the scalar values, call getScalarNames(). * * @param inputData the input value, in this case a date object * @return a list of one input double//from www . j a va2 s.co m */ public TDoubleList getScalars(DateTime inputData) { if (inputData == null) { throw new IllegalArgumentException("DateEncoder requires a valid Date object but got null"); } TDoubleList values = new TDoubleArrayList(); //Get the scalar values for each sub-field double timeOfDay = inputData.getHourOfDay() + inputData.getMinuteOfHour() / 60.0; // The day of week was 1 based, so convert to 0 based int dayOfWeek = inputData.getDayOfWeek() - 1; // + timeOfDay / 24.0 if (seasonEncoder != null) { // The day of year was 1 based, so convert to 0 based double dayOfYear = inputData.getDayOfYear() - 1; values.add(dayOfYear); } if (dayOfWeekEncoder != null) { values.add(dayOfWeek); } if (weekendEncoder != null) { //saturday, sunday or friday evening boolean isWeekend = dayOfWeek == 6 || dayOfWeek == 5 || (dayOfWeek == 4 && timeOfDay > 18); int weekend = isWeekend ? 1 : 0; values.add(weekend); } if (customDaysEncoder != null) { boolean isCustomDays = customDaysList.contains(dayOfWeek); int customDay = isCustomDays ? 1 : 0; values.add(customDay); } if (holidayEncoder != null) { // A "continuous" binary value. = 1 on the holiday itself and smooth ramp // 0->1 on the day before the holiday and 1->0 on the day after the holiday. double holidayness = 0; for (Tuple h : holidaysList) { //hdate is midnight on the holiday DateTime hdate = new DateTime(inputData.getYear(), (int) h.get(0), (int) h.get(1), 0, 0, 0); if (inputData.isAfter(hdate)) { Duration diff = new Interval(hdate, inputData).toDuration(); long days = diff.getStandardDays(); if (days == 0) { //return 1 on the holiday itself holidayness = 1; break; } else if (days == 1) { //ramp smoothly from 1 -> 0 on the next day holidayness = 1.0 - ((diff.getStandardSeconds() - 86400.0 * days) / 86400.0); break; } } else { //TODO This is not the same as when date.isAfter(hdate), why? Duration diff = new Interval(inputData, hdate).toDuration(); long days = diff.getStandardDays(); if (days == 0) { //ramp smoothly from 0 -> 1 on the previous day holidayness = 1.0 - ((diff.getStandardSeconds() - 86400.0 * days) / 86400.0); //TODO Why no break? } } } values.add(holidayness); } if (timeOfDayEncoder != null) { values.add(timeOfDay); } return values; }
From source file:org.sindicato.beans.UtilBean.java
public long diffDates(Date first, Date second) { long result = 0; if (first != null && second != null) { DateTime f = new DateTime(first); DateTime s = new DateTime(second); Duration d = new Duration(f, s); result = d.getStandardDays(); }/*from ww w .j av a2 s. c o m*/ return result; }
From source file:org.springframework.analytics.metrics.memory.InMemoryAggregateCounter.java
License:Apache License
private int daysInYear(int year) { Duration d = new Duration(new DateTime(year, 1, 1, 0, 0), new DateTime(year + 1, 1, 1, 0, 0)); return (int) d.getStandardDays(); }
From source file:SkynetBot.DBAccess.java
License:Open Source License
public String getLastSeen(String user, Channel channel) { Connection con;// ww w . j a v a 2 s. c om String last = "No records found for a resistance member named " + user + "."; DateTimeFormatter format = DateTimeFormat.forPattern("CCYY-MM-dd HH:mm:ss.S"); try { con = pool.getConnection(timeout); PreparedStatement s = con .prepareStatement("SELECT `last_seen` FROM `users` WHERE `name` = ? AND `channel` = ?"); s.setString(1, user.toLowerCase()); s.setString(2, channel.getName().toLowerCase()); s.executeQuery(); ResultSet rs = s.getResultSet(); while (rs.next()) { DateTime dateTime = format.parseDateTime(rs.getString("last_seen")); Duration duration = new Duration(dateTime, new DateTime()); if (duration.getStandardMinutes() < 120) { last = "Resistance member " + user + " was last seen " + duration.getStandardMinutes() + " minutes ago. Surveillance is ongoing."; } else if (duration.getStandardHours() < 48) { last = "Resistance member " + user + " was last seen " + duration.getStandardHours() + " hours ago. Surveillance is ongoing."; } else { last = "Resistance member " + user + " was last seen " + duration.getStandardDays() + " days ago. Surveillance is ongoing."; } } con.close(); } catch (Exception ex) { last = "ERROR! Data records corrupted! Resistance activity suspected."; Logger.getLogger(DBAccess.class.getName()).log(Level.SEVERE, null, ex); } return last; }