public AggregateKeyGenerator(String repoPrefix, String counterName, ReadableDateTime dateTime) { Assert.notNull(counterName, "Counter name name can not be null"); Assert.notNull(dateTime, "DateTime can not be null"); this.repoPrefix = repoPrefix; this.counterName = counterName; String timeStamp = dateTimeFormatter.print(dateTime); totalKey = key("total"); hourKey = key(timeStamp.substring(0, 10)); dayKey = key(timeStamp.substring(0, 8)); monthKey = key(timeStamp.substring(0, 6)); yearKey = key(timeStamp.substring(0, 4)); yearsKey = key("years"); minute = timeStamp.substring(10, 12); hour = timeStamp.substring(8, 10); day = timeStamp.substring(6, 8); month = timeStamp.substring(4, 6); year = timeStamp.substring(0, 4); }
/** * Set the value to a time only. * * @param t a time only * @param millis if true set milliseconds, otherwise do not set milliseconds */ public void setTimeOnly(ReadableDateTime t, boolean millis) { setDigits(t.getHourOfDay(), 2, 0); bytes[2] = ':'; setDigits(t.getMinuteOfHour(), 2, 3); bytes[5] = ':'; setDigits(t.getSecondOfMinute(), 2, 6); if (millis) { bytes[8] = '.'; setDigits(t.getMillisOfSecond(), 3, 9); bytes[12] = SOH; length = 12; } else { bytes[8] = SOH; length = 8; } offset = 0; }
/** * Set the value to a timestamp. * * @param t a timestamp * @param millis if true set milliseconds, otherwise do not set milliseconds */ public void setTimestamp(ReadableDateTime t, boolean millis) { setDigits(t.getYear(), 4, 0); setDigits(t.getMonthOfYear(), 2, 4); setDigits(t.getDayOfMonth(), 2, 6); bytes[8] = '-'; setDigits(t.getHourOfDay(), 2, 9); bytes[11] = ':'; setDigits(t.getMinuteOfHour(), 2, 12); bytes[14] = ':'; setDigits(t.getSecondOfMinute(), 2, 15); if (millis) { bytes[17] = '.'; setDigits(t.getMillisOfSecond(), 3, 18); bytes[21] = SOH; length = 21; } else { bytes[17] = SOH; length = 17; } offset = 0; }
/** * Wraps another chronology, with datetime limits. When withUTC or * withZone is called, the returned LimitChronology instance has * the same limits, except they are time zone adjusted. * * @param base base chronology to wrap * @param lowerLimit inclusive lower limit, or null if none * @param upperLimit exclusive upper limit, or null if none * @throws IllegalArgumentException if chronology is null or limits are invalid */ public static LimitChronology getInstance(Chronology base, ReadableDateTime lowerLimit, ReadableDateTime upperLimit) { if (base == null) { throw new IllegalArgumentException("Must supply a chronology"); } lowerLimit = lowerLimit == null ? null : lowerLimit.toDateTime(); upperLimit = upperLimit == null ? null : upperLimit.toDateTime(); if (lowerLimit != null && upperLimit != null) { if (!lowerLimit.isBefore(upperLimit)) { throw new IllegalArgumentException ("The lower limit must be come before than the upper limit"); } } return new LimitChronology(base, (DateTime)lowerLimit, (DateTime)upperLimit); }
public void testBigHashtable() { Converter[] array = new Converter[] { c1, c2, c3, c4, }; ConverterSet set = new ConverterSet(array); set.select(Boolean.class); set.select(Character.class); set.select(Byte.class); set.select(Short.class); set.select(Integer.class); set.select(Long.class); set.select(Float.class); set.select(Double.class); set.select(null); set.select(Calendar.class); set.select(GregorianCalendar.class); set.select(DateTime.class); set.select(DateMidnight.class); set.select(ReadableInstant.class); set.select(ReadableDateTime.class); set.select(ReadWritableInstant.class); // 16 set.select(ReadWritableDateTime.class); set.select(DateTime.class); assertEquals(4, set.size()); }
@SuppressWarnings("deprecation") @Override public ReadableDateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonToken t = jp.getCurrentToken(); if (t == JsonToken.VALUE_STRING) { String str = jp.getText().trim(); if (str.length() == 0) { // [JACKSON-360] return null; } // always use the tz in the string return ISODateTimeFormat.dateTime().withOffsetParsed().parseDateTime(str); } // TODO: in 2.4, use 'handledType()' throw ctxt.mappingException(getValueClass()); }
private Departure parseDeparture(Attributes attributes, ReadableDateTime time) { Departure.Builder departure = Departure.newBuilder(); departure.setName(attributes.getValue(XML_DEPARTURE_NAME)); // As no time zone is given, assume the one from the parameter String xmlDate = attributes.getValue(XML_DEPARTURE_DATE); String xmlTime = attributes.getValue(XML_DEPARTURE_TIME); LocalDateTime localTime = DATE_TIME_FORMATTER.parseLocalDateTime(xmlDate + xmlTime); departure.setTime(localTime.toDateTime(time.getZone())); String xmlDirection = attributes.getValue(XML_DEPARTURE_DIRECTION); if (xmlDirection != null) { departure.setDirection(xmlDirection); } return departure.build(); }
DateObjectValueSource(IndexFieldData<?> indexFieldData, MultiValueMode multiValueMode, String methodName, ToIntFunction<ReadableDateTime> function) { super(indexFieldData, multiValueMode); Objects.requireNonNull(methodName); this.methodName = methodName; this.function = function; }
@Deprecated public ReadableDateTime getDate() { deprecationLogger.deprecated("getDate on numeric fields is deprecated. Use a date field to get dates."); if (dates == null) { dates = new Dates(values); dates.refreshArray(); } return dates.getValue(); }
@Deprecated public List<ReadableDateTime> getDates() { deprecationLogger.deprecated("getDates on numeric fields is deprecated. Use a date field to get dates."); if (dates == null) { dates = new Dates(values); dates.refreshArray(); } return dates; }
/** * Fetch the first field value or 0 millis after epoch if there are no values. */ public ReadableDateTime getValue() { if (values.count() == 0) { return EPOCH; } return get(0); }
@Override public ReadableDateTime get(int index) { if (index >= values.count()) { throw new IndexOutOfBoundsException( "attempted to fetch the [" + index + "] date when there are only [" + values.count() + "] dates."); } return dates[index]; }
/** * Set the value to a date. * * @param d a date */ public void setDate(ReadableDateTime d) { setDigits(d.getYear(), 4, 0); setDigits(d.getMonthOfYear(), 2, 4); setDigits(d.getDayOfMonth(), 2, 6); bytes[8] = SOH; length = 8; offset = 0; }
/** * Append a timestamp to a string builder. * * @param t a timestamp * @param s a string builder */ public static void append(ReadableDateTime t, StringBuilder s) { s.append(t.getYear()); appendTwoDigits(t.getMonthOfYear(), s); appendTwoDigits(t.getDayOfMonth(), s); s.append('-'); appendTwoDigits(t.getHourOfDay(), s); s.append(':'); appendTwoDigits(t.getMinuteOfHour(), s); s.append(':'); appendTwoDigits(t.getSecondOfMinute(), s); s.append('.'); appendThreeDigits(t.getMillisOfSecond(), s); }
public static FDate valueOf(final ReadableDateTime jodaTime) { if (jodaTime != null) { return new FDate(jodaTime); } else { return null; } }
/** * * @param dateInstant * @param dateRangeStart * @param dateRangeEnd * @param netDefinition */ public TimeReferenceState(ReadableDateTime dateInstant, ReadableDateTime dateRangeStart, ReadableDateTime dateRangeEnd, String netDefinition) { super(); this.dateInstant = dateInstant; this.dateRangeStart = dateRangeStart; this.dateRangeEnd = dateRangeEnd; this.netDefinition = netDefinition; }
@Override public Object create(Object request, SpecimenContext context) { if (!(request.equals(ReadableInstant.class) || request.equals(ReadWritableInstant.class) || request.equals(ReadableDateTime.class) || request.equals(ReadWritableDateTime.class))) { return new NoSpecimen(); } DateTime date = (DateTime) context.resolve(DateTime.class); return new MutableDateTime(date); }
public DateTimeSerializeModule(){ super("DateTimeWithTimezone"); addDeserializer(DateTime.class, DateTimeDeserializer.forType(DateTime.class)); addDeserializer(ReadableDateTime.class, DateTimeDeserializer.forType(ReadableDateTime.class)); addDeserializer(ReadableInstant.class, DateTimeDeserializer.forType(ReadableInstant.class)); addSerializer(new DateTimeSerializer()); }
/** * Tests whether the automatic setting of field modified happens when * creating. */ @Test public void saveOrUpdate_shouldSetModified() { // first create an application and save it. Application app = this.getRandomUnsavedMockApp(); // Model tests should ensure that the constructor populates modified ReadableDateTime before = app.getModified(); try { // ... wait ... Thread.sleep(1); // ... then save appDao.saveOrUpdate(app); ReadableDateTime after = app.getModified(); assertNotEquals("before and after should be different", before, after); assertTrue("after should be greater than before", after.isAfter(before)); } catch (InterruptedException e) { fail("Caught exception while attempting to wait"); return; } }
/** * Tests whether saveOrUpdate cannot be tricked by explicitly setting field * modified. */ @Test public void saveOrUpdate_shouldAlwaysSetModified() { // first create an application and save it. Application app = this.getRandomUnsavedMockApp(); try { // ... wait ... Thread.sleep(1); // ... then update the modified field DateTime before = DateTime.now(); app.setModified(before); // ... wait ... Thread.sleep(1); // ... and only then save, modified should differ now appDao.saveOrUpdate(app); ReadableDateTime after = app.getModified(); // They should be different assertNotEquals(before, after); // after should be greater than before boolean isLater = before.compareTo(after) == -1; assertTrue(isLater); } catch (InterruptedException e) { fail("Caught exception while attempting to wait"); return; } }
/** * Tests whether an UPDATE results in updating the field modified. */ @Test public void saveOrUpdate_shouldUpdateModified() { // first create an application and save it. Application app = new Application("Some Name", "Some description"); appDao.saveOrUpdate(app); ReadableDateTime before = app.getModified(); try { Thread.sleep(1); // change the application app.setName("Some other name"); app.setDescription("Changed description"); appDao.saveOrUpdate(app); ReadableDateTime after = app.getModified(); // They should be different assertNotEquals(before, after); // after should be greater than before assertTrue(after.isAfter(before)); } catch (InterruptedException e) { fail("Caught exception while attempting to wait"); return; } }
public Collection<StdDeserializer<?>> provide() { StdDeserializer[] arrayOfStdDeserializer = new StdDeserializer[6]; arrayOfStdDeserializer[0] = new DateTimeDeserializer(DateTime.class); arrayOfStdDeserializer[1] = new DateTimeDeserializer(ReadableDateTime.class); arrayOfStdDeserializer[2] = new DateTimeDeserializer(ReadableInstant.class); arrayOfStdDeserializer[3] = new LocalDateDeserializer(); arrayOfStdDeserializer[4] = new LocalDateTimeDeserializer(); arrayOfStdDeserializer[5] = new DateMidnightDeserializer(); return Arrays.asList(arrayOfStdDeserializer); }
/** * Deserializes a JSON token (string) into a DateTime, using the supplied DateTimeFormatter. * * Note that not all of the superclass's functionality is implemented, i.e. conversion from integer rather than * string and adjustment for DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE. * * @param jsonParser The JSON parser. * @param context The deserialization context. * @return The deserialized DateTime. * @throws IOException If an error occurs */ @Override public ReadableDateTime deserialize(com.fasterxml.jackson.core.JsonParser jsonParser, DeserializationContext context) throws IOException { JsonToken token = jsonParser.getCurrentToken(); if (token == JsonToken.VALUE_STRING) { String str = jsonParser.getText().trim(); if (str.length() == 0) { return null; } return dateTimeFormatter.parseDateTime(str); } throw context.mappingException(getValueClass()); }
private static boolean isBusinessDay(ReadableDateTime date) { int dayOfWeek = date.getDayOfWeek(); if (dayOfWeek == DateTimeConstants.SATURDAY || dayOfWeek == DateTimeConstants.SUNDAY) { return false; } return true; }
static ValueSource getVariable(IndexFieldData<?> fieldData, String fieldName, String variable) { switch (variable) { case CENTURY_OF_ERA_VARIABLE: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getCenturyOfEra); case DAY_OF_MONTH_VARIABLE: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getDayOfMonth); case DAY_OF_WEEK_VARIABLE: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getDayOfWeek); case DAY_OF_YEAR_VARIABLE: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getDayOfYear); case ERA_VARIABLE: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getEra); case HOUR_OF_DAY_VARIABLE: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getHourOfDay); case MILLIS_OF_DAY_VARIABLE: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getMillisOfDay); case MILLIS_OF_SECOND_VARIABLE: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getMillisOfSecond); case MINUTE_OF_DAY_VARIABLE: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getMinuteOfDay); case MINUTE_OF_HOUR_VARIABLE: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getMinuteOfHour); case MONTH_OF_YEAR_VARIABLE: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getMonthOfYear); case SECOND_OF_DAY_VARIABLE: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getSecondOfDay); case SECOND_OF_MINUTE_VARIABLE: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getSecondOfMinute); case WEEK_OF_WEEK_YEAR_VARIABLE: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getWeekOfWeekyear); case WEEK_YEAR_VARIABLE: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getWeekyear); case YEAR_VARIABLE: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getYear); case YEAR_OF_CENTURY_VARIABLE: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getYearOfCentury); case YEAR_OF_ERA_VARIABLE: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, variable, ReadableDateTime::getYearOfEra); default: throw new IllegalArgumentException("Member variable [" + variable + "] does not exist for date object on field [" + fieldName + "]."); } }
static ValueSource getMethod(IndexFieldData<?> fieldData, String fieldName, String method) { switch (method) { case GETCENTURY_OF_ERA_METHOD: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getCenturyOfEra); case GETDAY_OF_MONTH_METHOD: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getDayOfMonth); case GETDAY_OF_WEEK_METHOD: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getDayOfWeek); case GETDAY_OF_YEAR_METHOD: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getDayOfYear); case GETERA_METHOD: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getEra); case GETHOUR_OF_DAY_METHOD: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getHourOfDay); case GETMILLIS_OF_DAY_METHOD: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getMillisOfDay); case GETMILLIS_OF_SECOND_METHOD: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getMillisOfSecond); case GETMINUTE_OF_DAY_METHOD: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getMinuteOfDay); case GETMINUTE_OF_HOUR_METHOD: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getMinuteOfHour); case GETMONTH_OF_YEAR_METHOD: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getMonthOfYear); case GETSECOND_OF_DAY_METHOD: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getSecondOfDay); case GETSECOND_OF_MINUTE_METHOD: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getSecondOfMinute); case GETWEEK_OF_WEEK_YEAR_METHOD: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getWeekOfWeekyear); case GETWEEK_YEAR_METHOD: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getWeekyear); case GETYEAR_METHOD: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getYear); case GETYEAR_OF_CENTURY_METHOD: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getYearOfCentury); case GETYEAR_OF_ERA_METHOD: return new DateObjectValueSource(fieldData, MultiValueMode.MIN, method, ReadableDateTime::getYearOfEra); default: throw new IllegalArgumentException("Member method [" + method + "] does not exist for date object on field [" + fieldName + "]."); } }
/** * Fetch the first value. Added for backwards compatibility with 5.x when date fields were {@link Longs}. */ @Deprecated public ReadableDateTime getDate() { deprecationLogger.deprecated("getDate is no longer necisary on date fields as the value is now a date."); return getValue(); }
/** * Fetch all the values. Added for backwards compatibility with 5.x when date fields were {@link Longs}. */ @Deprecated public List<ReadableDateTime> getDates() { deprecationLogger.deprecated("getDates is no longer necisary on date fields as the values are now dates."); return this; }
public void advanceTo(ReadableDateTime d) { DateTime dUtc = d.toDateTime().withZone(DateTimeZone.UTC); it.advanceTo(dateTimeToDateValue(dUtc)); }
static DateValue dateTimeToDateValue(ReadableDateTime dt) { return new DateTimeValueImpl( dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth(), dt.getHourOfDay(), dt.getMinuteOfHour(), dt.getSecondOfMinute()); }
private long[] getMinCountsForHour(String name, ReadableDateTime dateTime) { return getMinCountsForHour(name, dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getHourOfDay()); }
public FDate(final ReadableDateTime jodaTime) { this(jodaTime.getMillis()); }
/** * Overwrite this getter to set the {@link JsonIgnore} value to false * for this subclass. */ @Override @JsonIgnore(false) public ReadableDateTime getCreated() { return super.getCreated(); }