Java Code Examples for org.joda.time.DateTime#withSecondOfMinute()

The following examples show how to use org.joda.time.DateTime#withSecondOfMinute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MRStressTest.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
  DescriptiveStatistics stats = this.limiter.getRateStatsSinceLastReport();
  long now = System.currentTimeMillis();
  this.runs++;

  if (stats != null) {
    long key;
    if (this.relativeKey) {
      key = 15 * this.runs;
    } else {
      DateTime nowTime = new DateTime(now).withMillisOfSecond(0);
      DateTime rounded = nowTime.withSecondOfMinute(15 * (nowTime.getSecondOfMinute() / 15));
      key = rounded.getMillis() / 1000;
    }


    try {
      this.context.write(new LongWritable(key), new DoubleWritable(stats.getSum()));
    } catch (IOException | InterruptedException ioe) {
      log.error("Error: ", ioe);
    }
  }

}
 
Example 2
Source File: AbstractMetricsAccessor.java    From apiman with Apache License 2.0 6 votes vote down vote up
/**
 * Based on the given interval, create a "floor" value relative to the
 * given date.  This basically means zero'ing out certain fields (different
 * fields based on the interval type) and returning the modified date.
 * @param date
 * @param interval
 */
protected static DateTime floor(DateTime date, HistogramIntervalType interval) {
    DateTime rval = date.withMillisOfSecond(0);
    
    switch (interval) {
    case day:
        rval = rval.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
        break;
    case hour:
        rval = rval.withMinuteOfHour(0).withSecondOfMinute(0);
        break;
    case minute:
        rval = rval.withSecondOfMinute(0);
        break;
    case month:
        rval = rval.withDayOfMonth(1).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
        break;
    case week:
        rval = rval.withDayOfWeek(DateTimeConstants.MONDAY).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
        break;
    }
    
    return rval;
}
 
Example 3
Source File: HourTimeCalculator.java    From liteflow with Apache License 2.0 5 votes vote down vote up
@Override
public Date getStartTime() {
    DateTime dateTime = new DateTime(time);
    dateTime = dateTime.withMinuteOfHour(CommonConstants.ZERO);
    dateTime = dateTime.withSecondOfMinute(CommonConstants.ZERO);
    return dateTime.toDate();
}
 
Example 4
Source File: HourTimeCalculator.java    From liteflow with Apache License 2.0 5 votes vote down vote up
@Override
public Date getEndTime() {
    DateTime dateTime = new DateTime(time);
    dateTime = dateTime.withMinuteOfHour(CommonConstants.FIFTY_NINE);
    dateTime = dateTime.withSecondOfMinute(CommonConstants.FIFTY_NINE);
    return dateTime.toDate();
}
 
Example 5
Source File: TestDateTimeFunctionsBase.java    From presto with Apache License 2.0 4 votes vote down vote up
@Test
public void testTruncateTimestamp()
{
    DateTime result = TIMESTAMP;
    result = result.withMillisOfSecond(0);
    assertFunction("date_trunc('second', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session));

    result = result.withSecondOfMinute(0);
    assertFunction("date_trunc('minute', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session));

    result = result.withMinuteOfHour(0);
    assertFunction("date_trunc('hour', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session));

    result = result.withHourOfDay(0);
    assertFunction("date_trunc('day', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session));

    result = result.withDayOfMonth(20);
    assertFunction("date_trunc('week', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session));

    result = result.withDayOfMonth(1);
    assertFunction("date_trunc('month', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session));

    result = result.withMonthOfYear(7);
    assertFunction("date_trunc('quarter', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session));

    result = result.withMonthOfYear(1);
    assertFunction("date_trunc('year', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(result, session));

    result = WEIRD_TIMESTAMP;
    result = result.withMillisOfSecond(0);
    assertFunction("date_trunc('second', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));

    result = result.withSecondOfMinute(0);
    assertFunction("date_trunc('minute', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));

    result = result.withMinuteOfHour(0);
    assertFunction("date_trunc('hour', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));

    result = result.withHourOfDay(0);
    assertFunction("date_trunc('day', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));

    result = result.withDayOfMonth(20);
    assertFunction("date_trunc('week', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));

    result = result.withDayOfMonth(1);
    assertFunction("date_trunc('month', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));

    result = result.withMonthOfYear(7);
    assertFunction("date_trunc('quarter', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));

    result = result.withMonthOfYear(1);
    assertFunction("date_trunc('year', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));
}
 
Example 6
Source File: MinuteTimeCalculator.java    From liteflow with Apache License 2.0 4 votes vote down vote up
@Override
public Date getStartTime() {
    DateTime dateTime = new DateTime(time);
    dateTime = dateTime.withSecondOfMinute(CommonConstants.ZERO);
    return dateTime.toDate();
}
 
Example 7
Source File: MinuteTimeCalculator.java    From liteflow with Apache License 2.0 4 votes vote down vote up
@Override
public Date getEndTime() {
    DateTime dateTime = new DateTime(time);
    dateTime = dateTime.withSecondOfMinute(CommonConstants.FIFTY_NINE);
    return dateTime.toDate();
}
 
Example 8
Source File: DateTruncTransformFunctionTest.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
private void testDateTrunc(Schema schema)
    throws Exception {

  DateTime result = TIMESTAMP;
  result = result.withMillisOfSecond(0);
  testDateTruncHelper(schema, TIMESTAMP_ISO8601_STRING, "second", UTC_TIME_ZONE.getID(), result.getMillis());

  result = result.withSecondOfMinute(0);
  testDateTruncHelper(schema, TIMESTAMP_ISO8601_STRING, "minute", UTC_TIME_ZONE.getID(), result.getMillis());

  result = result.withMinuteOfHour(0);
  testDateTruncHelper(schema, TIMESTAMP_ISO8601_STRING, "hour", UTC_TIME_ZONE.getID(), result.getMillis());

  result = result.withHourOfDay(0);
  testDateTruncHelper(schema, TIMESTAMP_ISO8601_STRING, "day", UTC_TIME_ZONE.getID(), result.getMillis());

  // ISO8601 week begins on Monday. For this timestamp (2001-08-22), 20th is the Monday of that week
  result = result.withDayOfMonth(20);
  testDateTruncHelper(schema, TIMESTAMP_ISO8601_STRING, "week", UTC_TIME_ZONE.getID(), result.getMillis());

  result = result.withDayOfMonth(1);
  testDateTruncHelper(schema, TIMESTAMP_ISO8601_STRING, "month", UTC_TIME_ZONE.getID(), result.getMillis());

  result = result.withMonthOfYear(7);
  testDateTruncHelper(schema, TIMESTAMP_ISO8601_STRING, "quarter", UTC_TIME_ZONE.getID(), result.getMillis());

  result = result.withMonthOfYear(1);
  testDateTruncHelper(schema, TIMESTAMP_ISO8601_STRING, "year", UTC_TIME_ZONE.getID(), result.getMillis());

  result = WEIRD_TIMESTAMP;
  result = result.withMillisOfSecond(0);
  testDateTruncHelper(schema, WEIRD_TIMESTAMP_ISO8601_STRING, "second", WEIRD_DATE_TIME_ZONE.getID(),
      result.getMillis());

  result = result.withSecondOfMinute(0);
  testDateTruncHelper(schema, WEIRD_TIMESTAMP_ISO8601_STRING, "minute", WEIRD_DATE_TIME_ZONE.getID(),
      result.getMillis());

  result = result.withMinuteOfHour(0);
  testDateTruncHelper(schema, WEIRD_TIMESTAMP_ISO8601_STRING, "hour", WEIRD_DATE_TIME_ZONE.getID(),
      result.getMillis());

  result = result.withHourOfDay(0);
  testDateTruncHelper(schema, WEIRD_TIMESTAMP_ISO8601_STRING, "day", WEIRD_DATE_TIME_ZONE.getID(),
      result.getMillis());

  result = result.withDayOfMonth(20);
  testDateTruncHelper(schema, WEIRD_TIMESTAMP_ISO8601_STRING, "week", WEIRD_DATE_TIME_ZONE.getID(),
      result.getMillis());

  result = result.withDayOfMonth(1);
  testDateTruncHelper(schema, WEIRD_TIMESTAMP_ISO8601_STRING, "month", WEIRD_DATE_TIME_ZONE.getID(),
      result.getMillis());

  result = result.withMonthOfYear(7);
  testDateTruncHelper(schema, WEIRD_TIMESTAMP_ISO8601_STRING, "quarter", WEIRD_DATE_TIME_ZONE.getID(),
      result.getMillis());

  result = result.withMonthOfYear(1);
  testDateTruncHelper(schema, WEIRD_TIMESTAMP_ISO8601_STRING, "year", WEIRD_DATE_TIME_ZONE.getID(),
      result.getMillis());
}