Example usage for org.joda.time LocalDateTime LocalDateTime

List of usage examples for org.joda.time LocalDateTime LocalDateTime

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime LocalDateTime.

Prototype

public LocalDateTime(Object instant) 

Source Link

Document

Constructs an instance from an Object that represents a datetime.

Usage

From source file:eu.trentorise.game.model.PointConcept.java

License:Apache License

/**
 * The method returns the PeriodInstance relative to the index.
 * //from w ww  . j  ava 2 s  .  c om
 * @param periodIdentifier
 *            identifier of period
 * @param instanceIndex
 *            index of instance
 * @return PeriodInstance bound to the index or null if there is not
 *         PeriodInstance at that index
 */
public PeriodInstance getPeriodInstance(String periodIdentifier, int instanceIndex) {
    PeriodInstance result = null;
    PeriodInternal p = periods.get(periodIdentifier);
    if (p != null) {
        if (p.period == -1 && instanceIndex > 0) {
            result = new PeriodInstanceImpl(p.getEnd().map(e -> e.getTime()).orElse(-1L), -1L);
        } else {
            LocalDateTime dateCursor = new LocalDateTime(p.start);
            dateCursor = dateCursor.withPeriodAdded(new org.joda.time.Period(p.period), instanceIndex);
            result = getPeriodInstance(periodIdentifier, dateCursor.toDate().getTime());
        }
    }

    return result;
}

From source file:fi.helsinki.opintoni.repository.CustomAuditEventRepository.java

License:Open Source License

@Bean
public AuditEventRepository auditEventRepository() {
    return new AuditEventRepository() {

        @Inject//  w  w  w .j  a  v a2  s  .c  o m
        private AuditEventConverter auditEventConverter;

        @Override
        public List<AuditEvent> find(String principal, Date after) {
            Iterable<PersistentAuditEvent> persistentAuditEvents;
            if (principal == null && after == null) {
                persistentAuditEvents = persistenceAuditEventRepository.findAll();
            } else if (after == null) {
                persistentAuditEvents = persistenceAuditEventRepository.findByPrincipal(principal);
            } else {
                persistentAuditEvents = persistenceAuditEventRepository
                        .findByPrincipalAndAuditEventDateAfter(principal, new LocalDateTime(after));
            }
            return auditEventConverter.convertToAuditEvent(persistentAuditEvents);
        }

        @Override
        @Transactional(propagation = Propagation.REQUIRES_NEW)
        public void add(AuditEvent event) {
            PersistentAuditEvent persistentAuditEvent = new PersistentAuditEvent();
            persistentAuditEvent.setPrincipal(event.getPrincipal());
            persistentAuditEvent.setAuditEventType(event.getType());
            persistentAuditEvent.setAuditEventDate(new LocalDateTime(event.getTimestamp()));
            persistentAuditEvent.setData(auditEventConverter.convertDataToStrings(event.getData()));

            persistenceAuditEventRepository.save(persistentAuditEvent);
        }
    };
}

From source file:griffon.plugins.jodatime.editors.LocalDateTimePropertyEditor.java

License:Apache License

protected void setValueInternal(Object value) {
    if (null == value) {
        super.setValueInternal(null);
    } else if (value instanceof LocalDateTime) {
        super.setValueInternal(value);
    } else if (value instanceof LocalDate) {
        super.setValueInternal(((LocalDate) value).toDateTimeAtStartOfDay());
    } else if (value instanceof LocalTime) {
        super.setValueInternal(((LocalTime) value).toDateTimeToday());
    } else if (value instanceof DateMidnight) {
        super.setValueInternal(((DateMidnight) value).toDateTime().toLocalDateTime());
    } else if (value instanceof CharSequence) {
        handleAsString(String.valueOf(value));
    } else if (value instanceof Calendar) {
        super.setValueInternal(LocalDateTime.fromCalendarFields((Calendar) value));
    } else if (value instanceof Date) {
        super.setValueInternal(LocalDateTime.fromDateFields((Date) value));
    } else if (value instanceof Number) {
        super.setValueInternal(new LocalDateTime(((Number) value).longValue()));
    } else {/* w  ww  .ja v a2s. com*/
        throw illegalValue(value, LocalDateTime.class);
    }
}

From source file:griffon.plugins.jodatime.editors.LocalDateTimePropertyEditor.java

License:Apache License

private void handleAsString(String str) {
    if (isBlank(str)) {
        super.setValueInternal(null);
        return;/*from w  w  w .  ja  va2  s .co  m*/
    }

    try {
        super.setValueInternal(new LocalDateTime(Long.parseLong(str)));
        return;
    } catch (NumberFormatException nfe) {
        nfe.printStackTrace();
        // ignore
    }

    try {
        super.setValueInternal(LocalDateTime.parse(str));
    } catch (IllegalArgumentException e) {
        throw illegalValue(str, LocalDateTime.class, e);
    }
}

From source file:griffon.plugins.jodatime.JodatimeExtension.java

License:Apache License

public static LocalDateTime toLocalDateTime(Date date) {
    return new LocalDateTime(date);
}

From source file:griffon.plugins.jodatime.JodatimeExtension.java

License:Apache License

public static LocalDateTime toLocalDateTime(Calendar calendar) {
    return new LocalDateTime(calendar);
}

From source file:griffon.plugins.jodatime.JodatimeExtension.java

License:Apache License

public static LocalDateTime toLocalDateTime(Number number) {
    return new LocalDateTime(abs(number.longValue()));
}

From source file:griffon.plugins.scaffolding.atoms.LocalDateTimeValue.java

License:Apache License

@Override
public void setValue(Object value) {
    if (value == null || value instanceof LocalDateTime) {
        super.setValue(value);
    } else if (value instanceof DateTime) {
        super.setValue(((DateTime) value).toLocalDateTime());
    } else if (value instanceof DateMidnight) {
        super.setValue(((DateMidnight) value).toDateTime().toLocalDateTime());
    } else if (value instanceof Instant) {
        super.setValue(((Instant) value).toDateTime().toLocalDateTime());
    } else if (value instanceof LocalDate) {
        super.setValue(((LocalDate) value).toDateTimeAtStartOfDay().toLocalDateTime());
    } else if (value instanceof Calendar || value instanceof Date) {
        super.setValue(new LocalDateTime(value));
    } else if (value instanceof Number) {
        super.setValue(new LocalDateTime(((Number) value).longValue()));
    } else {//from   w  w w  . ja v  a2s.c om
        throw new IllegalArgumentException("Invalid value " + value);
    }
}

From source file:io.github.benas.jpopulator.randomizers.joda.DefaultJodaLocalDateTimeRandomizer.java

License:Open Source License

@Override
public LocalDateTime getRandomValue() {
    return new LocalDateTime(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime());
}

From source file:io.github.benas.randombeans.randomizers.jodatime.JodaTimeLocalDateTimeRandomizer.java

License:Open Source License

@Override
public LocalDateTime getRandomValue() {
    return new LocalDateTime(Constants.DATE_RANGE_RANDOMIZER.getRandomValue().getTime());
}