List of usage examples for org.joda.time DateMidnight DateMidnight
public DateMidnight(Object instant)
From source file:DateMidnightTypeAdapter.java
License:Apache License
@Override public DateMidnight read(JsonReader in) throws IOException { if (in.peek() == JsonToken.NULL) { in.nextNull();/*from w w w. jav a 2 s . com*/ return null; } return new DateMidnight(in.nextString()); }
From source file:be.fedict.hsm.admin.webapp.CertificateView.java
License:Open Source License
public int getDaysLeft() { DateTime notAfter = new DateTime(this.certificate.getNotAfter()); DateTime now = new DateTime(); Days days = Days.daysBetween(new DateMidnight(now), new DateMidnight(notAfter)); return days.getDays(); }
From source file:ch.thn.gedcom.GedcomHelper.java
License:Apache License
/** * Calculates the age of the person between the given birthDate and the toDate * //ww w. j av a2 s . c o m * @param fromDate * @param toDate * @return */ public static int getAge(Date fromDate, Date toDate) { if (fromDate == null || toDate == null) { return 0; } DateMidnight bd = new DateMidnight(fromDate); DateTime now = new DateTime(toDate); Years age = Years.yearsBetween(bd, now); return age.getYears(); }
From source file:com.alliander.osgp.domain.core.validation.joda.FutureValidator.java
License:Open Source License
@Override public boolean isValid(final ReadableInstant value, final ConstraintValidatorContext context) { if (value == null) { return true; }//from ww w . j a v a 2s.c o m final DateTime checkDate = new DateMidnight(DateTimeZone.UTC).toDateTime(); return value.isEqual(checkDate) || value.isAfter(checkDate); }
From source file:com.alliander.osgp.domain.core.validation.joda.PastValidator.java
License:Open Source License
@Override public boolean isValid(final ReadableInstant value, final ConstraintValidatorContext context) { if (value == null) { return true; }//w w w .ja va 2 s . c o m final DateMidnight checkDate = new DateMidnight(DateTimeZone.UTC); return value.isEqual(checkDate) || value.isBefore(checkDate); }
From source file:com.billing.ng.entities.BillingCycle.java
License:Open Source License
/** * Returns true if the given date is between the start and end date * for this billing cycle.//from w ww . jav a 2s.co m * * @param date active date * @return true if cycle is active for the given date, false if not */ @SuppressWarnings({ "RedundantIfStatement" }) // verbose if statements for clarity public boolean isActive(DateMidnight date) { if (getStart() != null && new DateMidnight(getStart()).isAfter(date)) return false; if (getEnd() != null && new DateMidnight(getEnd()).isBefore(date)) return false; return true; }
From source file:com.billing.ng.entities.BillingCycle.java
License:Open Source License
/** * The initial starting instant of the entire billing cycle. The start instant is * the first instance of the cycle start day after (or equal to) the cycle start date. * * @return starting instant of this billing cycle *///from w w w . j a v a2 s . c o m public DateMidnight getStartInstant() { DateMidnight start = new DateMidnight(getStart()); Period period = getBillingPeriod().getPeriodOfTime(); // first possible start date for a period DateMidnight calculated = getCycleStartDay() != LAST_DAY_OF_MONTH ? start.dayOfMonth().setCopy(getCycleStartDay()) : start.dayOfMonth().withMaximumValue(); // increment by billing period interval until a valid start date is found while (calculated.isBefore(start)) { calculated = calculated.plus(period); } return calculated; }
From source file:com.billing.ng.entities.BillingCycle.java
License:Open Source License
/** * The end instant of the entire billing cycle. The end instant is the last day * of the billing cycle, effectively {@link #getEnd()}. * * If billing cycle end is null, this method will return the start instant * with the year {@link BillingPeriod} incremented to it's maximum value. * * @return ending instant of this billing cycle */// w ww .j a v a 2 s . co m public DateMidnight getEndInstant() { return getEnd() == null ? getStartInstant().year().withMaximumValue() : new DateMidnight(getEnd()); }
From source file:com.enonic.cms.core.search.query.IndexValueConverter.java
License:Open Source License
public static ReadableDateTime toDate(String value) { value = value.toUpperCase();//www . ja va 2 s . co m Date dateTimeByFullFormat = toDate(value, FULL_DATE_FORMAT); if (dateTimeByFullFormat != null) { final DateTime dateTimeByFullFormatTimeZone = toDateTime(value, FULL_DATE_FORMAT_WITH_TIME_ZONE); if (dateTimeByFullFormatTimeZone != null) { return dateTimeByFullFormatTimeZone; } return new DateTime(dateTimeByFullFormat); } Date dateTimeByDateTimeWithSecsFormat = toDate(value, DATETIME_WITH_SECS_FORMAT); if (dateTimeByDateTimeWithSecsFormat != null) { return new DateTime(dateTimeByDateTimeWithSecsFormat); } Date dateTimeByDateTimeWithoutSecsFormat = toDate(value, DATETIME_WITHOUT_SECS_FORMAT); if (dateTimeByDateTimeWithoutSecsFormat != null) { return new DateTime(dateTimeByDateTimeWithoutSecsFormat); } Date dateByDateFormat = toDate(value, DATE_FORMAT); if (dateByDateFormat != null) { // We use DateMidnight to later recognise that user have not specified time return new DateMidnight(dateByDateFormat); } return null; }
From source file:com.enonic.cms.domain.content.index.util.ValueConverter.java
License:Open Source License
public static ReadableDateTime toDate(String value) { value = value.toUpperCase();//from ww w. j a va 2 s.c o m Date dateTimeByFullFormat = toDate(value, FULL_DATE_FORMAT); if (dateTimeByFullFormat != null) { return new DateTime(dateTimeByFullFormat); } Date dateTimeByDateTimeWithSecsFormat = toDate(value, DATETIME_WITH_SECS_FORMAT); if (dateTimeByDateTimeWithSecsFormat != null) { return new DateTime(dateTimeByDateTimeWithSecsFormat); } Date dateTimeByDateTimeWithoutSecsFormat = toDate(value, DATETIME_WITHOUT_SECS_FORMAT); if (dateTimeByDateTimeWithoutSecsFormat != null) { return new DateTime(dateTimeByDateTimeWithoutSecsFormat); } Date dateByDateFormat = toDate(value, DATE_FORMAT); if (dateByDateFormat != null) { // We use DateMidnight to later recognise that user have not specified time return new DateMidnight(dateByDateFormat); } return null; }