List of usage examples for org.joda.time DateTimeUtils toJulianDayNumber
public static final long toJulianDayNumber(long epochMillis)
From source file:de.kuschku.libquassel.primitives.serializers.DateTimeSerializer.java
License:Open Source License
@Override public void serialize(@NonNull final ByteChannel channel, @NonNull final DateTime data) throws IOException { final boolean isUTC; final DateTimeZone zone = data.getZone(); if (Objects.equals(zone, DateTimeZone.UTC)) { isUTC = true;/*from w ww . j a v a2 s .c om*/ } else if (Objects.equals(zone, DateTimeZone.getDefault())) { isUTC = false; // TODO: Add serialization for other timezones } else { throw new IllegalArgumentException( "Serialization of timezones except for local and UTC is not supported"); } IntSerializer.get().serialize(channel, (int) DateTimeUtils.toJulianDayNumber(data.getMillis())); IntSerializer.get().serialize(channel, data.getMillisOfDay()); BoolSerializer.get().serialize(channel, isUTC); }
From source file:org.jruby.ext.date.RubyDate.java
License:LGPL
public final long getJulianDayNumber() { return DateTimeUtils.toJulianDayNumber(dt.getMillis() + off * 1000); }
From source file:org.jruby.ext.date.RubyDate.java
License:LGPL
@JRubyMethod public IRubyObject start(ThreadContext context) { Chronology chrono = dt.getChronology(); if (chrono instanceof GregorianChronology) { return getMetaClass().getConstant("GREGORIAN"); // Date::GREGORIAN (-Date::Infinity) }/*from w ww. j a v a 2s . c om*/ if (chrono instanceof JulianChronology) { return getMetaClass().getConstant("JULIAN"); // Date::JULIAN (+Date::Infinity) } long cutover = DateTimeUtils.toJulianDayNumber(((GJChronology) chrono).getGregorianCutover().getMillis()); return new RubyFixnum(context.runtime, cutover); }
From source file:org.segrada.service.repository.orientdb.OrientDbPeriodRepository.java
License:Apache License
@Override public List<IPeriod> findWithin(DateTime start, DateTime end) { // convert and call base method Long jdStart = null, jdEnd = null; if (start != null) jdStart = DateTimeUtils.toJulianDayNumber(start.getMillis()); if (end != null) jdEnd = DateTimeUtils.toJulianDayNumber(end.getMillis()); return findWithin(jdStart, jdEnd); }
From source file:org.segrada.util.FlexibleDateParser.java
License:Apache License
/** * Parse input to Julian Day number/*from w w w .j a v a 2 s . co m*/ * @param input string * @param type calendar type, e.g. "G" or "J" * @param high true to get last instance of parsed time, first otherwise * @return julian day number */ public Long inputToJd(@Nullable String input, String type, boolean high) { // sanity check if (input == null || "".equals(input)) return high ? Long.MAX_VALUE : Long.MIN_VALUE; try { DateTime date = inputFormatter.withChronology(getChronologyFromType(type)) .withLocale(Locale.getDefault()).withZoneUTC().parseDateTime(input); // get last time instance of the input if (high) { // guess input pattern by counting character occurences int count = Math.max(StringUtils.countMatches(input, "."), Math.max(StringUtils.countMatches(input, "/"), StringUtils.countMatches(input, "-"))); if (count == 0) // year only date = date.withMonthOfYear(12).withDayOfMonth(31); else if (count == 1) { // year/month date = date.withDayOfMonth(date.dayOfMonth().getMaximumValue()); } // day/month/year as is } return DateTimeUtils.toJulianDayNumber(date.getMillis()); } catch (Exception e) { logger.warn("Could not parse to DateTime: " + input + " (type = " + type + ")", e); } return null; }