List of usage examples for org.joda.time Days getDays
public int getDays()
From source file:models.AbstractBaseTrans.java
License:Open Source License
@Override @Transient//from ww w . j av a 2s . c o m public String checkEditingConstraints() { if (!CacheUtils.isSpecialUser()) { AdminUserGroup group = CacheUtils.getUser().userGroup; if (id != null && group.editingTimeout > 0) { org.joda.time.DateTime today = new org.joda.time.DateTime(new Date()); org.joda.time.DateTime insertAtDT = new org.joda.time.DateTime(insertAt); Days days = Days.daysBetween(insertAtDT, today); if (days.getDays() > group.editingTimeout) { return Messages.get("editing_timeout.alert", group.editingTimeout); } } org.joda.time.DateTime today = new org.joda.time.DateTime(new Date()); org.joda.time.DateTime transDateDT = new org.joda.time.DateTime(transDate); Days days = Days.daysBetween(transDateDT, today); if (days.getDays() != 0 && !group.hasEditDifDate) { return Messages.get("editing_difdate.alert"); } } if (isUsedForElse("trans_no", transNo)) { return Messages.get("trans.no") + " " + Messages.get("not.unique", transNo); } return super.checkEditingConstraints(); }
From source file:models.JWeek.java
License:Apache License
/** * Gets the JiVitA week./* w w w .j av a2s .c o m*/ * * @return the JiVitA week */ public int getJWeek() { Days days = Days.daysBetween(jivitaEpoch, new DateTime(this)); double dDays = (double) days.getDays(); double weeks = Math.ceil(dDays / 7.0d); return (int) weeks; }
From source file:net.sourceforge.fenixedu.domain.accessControl.NotUpdatedAlumniInfoForSpecificDaysGroup.java
License:Open Source License
private boolean notRecentlyUpdated(DateTime now, DateTime lastModifiedDate) { Days days = Days.daysBetween(lastModifiedDate, now); return days.getDays() > daysNotUpdated; }
From source file:net.technicpack.launcher.ui.components.news.AuthorshipWidget.java
License:Open Source License
private String getDateText(Date date) { LocalDate posted = new LocalDate(date.getTime()); LocalDate now = new LocalDate(); Years yearsSince = Years.yearsBetween(posted, now); Months monthsSince = Months.monthsBetween(posted, now); Days daysSince = Days.daysBetween(posted, now); Hours hoursSince = Hours.hoursBetween(posted, now); Minutes minutesSince = Minutes.minutesBetween(posted, now); if (yearsSince.getYears() > 1) return resources.getString("time.years", Integer.toString(yearsSince.getYears())); else if (yearsSince.getYears() == 1) return resources.getString("time.year"); else if (monthsSince.getMonths() > 1) return resources.getString("time.months", Integer.toString(monthsSince.getMonths())); else if (monthsSince.getMonths() == 1) return resources.getString("time.month"); else if (daysSince.getDays() > 1) return resources.getString("time.days", Integer.toString(daysSince.getDays())); else if (daysSince.getDays() == 1) return resources.getString("time.day"); else if (hoursSince.getHours() > 1) return resources.getString("time.hours", Integer.toString(hoursSince.getHours())); else if (hoursSince.getHours() == 1) return resources.getString("time.hour"); else if (minutesSince.getMinutes() > 1) return resources.getString("time.minutes", Integer.toString(minutesSince.getMinutes())); else//from w ww. j av a2 s.c o m return resources.getString("time.minute"); }
From source file:net.tourbook.ui.views.calendar.CalendarGraph.java
License:Open Source License
public void gotoToday() { _dt = new DateTime(); final Days d = Days.daysBetween(new DateTime(0), _dt); _selectedItem = new Selection((long) d.getDays(), SelectionType.DAY); gotoDate(_dt);// ww w . ja v a 2 s . c om }
From source file:org.apache.beam.sdk.io.clickhouse.ClickHouseWriter.java
License:Apache License
@SuppressWarnings("unchecked") static void writeValue(ClickHouseRowBinaryStream stream, ColumnType columnType, Object value) throws IOException { switch (columnType.typeName()) { case FIXEDSTRING: byte[] bytes; if (value instanceof String) { bytes = ((String) value).getBytes(Charsets.UTF_8); } else {/*from ww w . j ava 2s . c o m*/ bytes = ((byte[]) value); } stream.writeBytes(bytes); break; case FLOAT32: stream.writeFloat32((Float) value); break; case FLOAT64: stream.writeFloat64((Double) value); break; case INT8: stream.writeInt8((Byte) value); break; case INT16: stream.writeInt16((Short) value); break; case INT32: stream.writeInt32((Integer) value); break; case INT64: stream.writeInt64((Long) value); break; case STRING: stream.writeString((String) value); break; case UINT8: stream.writeUInt8((Short) value); break; case UINT16: stream.writeUInt16((Integer) value); break; case UINT32: stream.writeUInt32((Long) value); break; case UINT64: stream.writeUInt64((Long) value); break; case ENUM8: Integer enum8 = columnType.enumValues().get((String) value); Preconditions.checkNotNull(enum8, "unknown enum value '" + value + "', possible values: " + columnType.enumValues()); stream.writeInt8(enum8); break; case ENUM16: Integer enum16 = columnType.enumValues().get((String) value); Preconditions.checkNotNull(enum16, "unknown enum value '" + value + "', possible values: " + columnType.enumValues()); stream.writeInt16(enum16); break; case DATE: Days epochDays = Days.daysBetween(EPOCH_INSTANT, (ReadableInstant) value); stream.writeUInt16(epochDays.getDays()); break; case DATETIME: long epochSeconds = ((ReadableInstant) value).getMillis() / 1000L; stream.writeUInt32(epochSeconds); break; case ARRAY: List<Object> values = (List<Object>) value; stream.writeUnsignedLeb128(values.size()); for (Object arrayValue : values) { writeValue(stream, columnType.arrayElementType(), arrayValue); } break; } }
From source file:org.apache.pig.piggybank.evaluation.datetime.diff.ISODaysBetween.java
License:Apache License
@Override public Long exec(Tuple input) throws IOException { if (input == null || input.size() < 2) { return null; }/*w w w . j a v a2 s. c o m*/ // Set the time to default or the output is in UTC DateTimeZone.setDefault(DateTimeZone.UTC); DateTime startDate = new DateTime(input.get(0).toString()); DateTime endDate = new DateTime(input.get(1).toString()); // Larger date first Days d = Days.daysBetween(endDate, startDate); long days = d.getDays(); return days; }
From source file:org.ash.history.CalendarH.java
License:Open Source License
/** * Get fragged days for Calendar./* w ww. j a va 2 s . c o m*/ * * @param begin0 * @param end0 * @return */ private long[] getFraggedDays(long begin0, long end0) { DateTime begin = new DateTime(begin0); DateTime end = new DateTime(end0); DateTime beginTmp = new DateTime(begin); DateTime beginDayPlus0000 = new DateTime(beginTmp.getYear(), beginTmp.getMonthOfYear(), beginTmp.getDayOfMonth(), 0, 0, 0, 0); DateTime endTmp = new DateTime(end); DateTime endPlus2359 = new DateTime(endTmp.getYear(), endTmp.getMonthOfYear(), endTmp.getDayOfMonth(), 23, 59, 59, 999); Interval interval = new Interval(beginDayPlus0000, endPlus2359); Days days = Days.daysIn(interval); int daysBetween = days.getDays(); long[] flaggedDates = new long[daysBetween + 1]; DateTime tmp = new DateTime(begin); // Load days. for (int i = 0; i <= daysBetween; i++) { DateTime tmp1 = tmp.plusDays(i); flaggedDates[i] = tmp1.getMillis(); } return flaggedDates; }
From source file:org.ash.history.MainPreview.java
License:Open Source License
/** * Set date format for x Axis and range data. * //w ww . j a v a 2s . c o m * @param databaseHistory */ private void setDateFormatXAxis(long start, long end) { DateFormat dateFormatDate = new SimpleDateFormat("d"); DateFormat dateFormatMonth = new SimpleDateFormat("MM"); DateFormat dateFormatData = new SimpleDateFormat("dd.MM.yyyy"); if ((dateFormatDate.format(start).equalsIgnoreCase(dateFormatDate.format(end))) && (dateFormatMonth.format(start).equalsIgnoreCase(dateFormatMonth.format(end)))) { setDateFormatXAxis("HH:mm"); setRangeData(dateFormatData.format(start)); } else { DateTime startTemp = new DateTime(start); DateTime endTemp = new DateTime(end); Interval interval = new Interval(startTemp, endTemp); Days days = Days.daysIn(interval); if (days.getDays() < 2) { setDateFormatXAxis("HH:mm"); setRangeData(dateFormatData.format(start) + "-" + dateFormatData.format(end)); } else { setDateFormatXAxis("EEE d, HH"); setRangeData(dateFormatData.format(start) + "-" + dateFormatData.format(end)); } } }
From source file:org.encuestame.utils.DateUtil.java
License:Apache License
/** * Get Days Between Dates./* w ww .j av a2 s . c om*/ * @param startDate * @return */ public static Integer getDaysBetweenDates(final Date startDate) { final DateTime currentDate = new DateTime(); final DateTime storedDate = new DateTime(startDate); final Days daysBetween = Days.daysBetween(storedDate, currentDate); return daysBetween.getDays(); }