Java Code Examples for java.time.temporal.ChronoUnit#HALF_DAYS

The following examples show how to use java.time.temporal.ChronoUnit#HALF_DAYS . 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: TCKPeriod.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 2
Source File: TCKPeriod.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@DataProvider
public static Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 3
Source File: ClusterEventEncoderTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@Test
void testStateChangeLength()
{
    final ChronoUnit from = ChronoUnit.CENTURIES;
    final ChronoUnit to = ChronoUnit.HALF_DAYS;
    final String payload = from.name() + STATE_SEPARATOR + to.name();

    assertEquals(payload.length() + (SIZE_OF_INT * 2), stateChangeLength(from, to));
}
 
Example 4
Source File: PackedLocalTime.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
public static int truncatedTo(TemporalUnit unit, int packedTime) {
  if (unit == ChronoUnit.NANOS || unit == ChronoUnit.MILLIS) {
    return packedTime;
  }
  Duration unitDur = unit.getDuration();
  if (unitDur.getSeconds() > SECONDS_PER_DAY) {
    throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation");
  }

  int hour = PackedLocalTime.getHour(packedTime);
  int minute = PackedLocalTime.getMinute(packedTime);
  int second = PackedLocalTime.getSecond(packedTime);
  int milli = 0;

  if (unit == ChronoUnit.DAYS) {
    hour = 0;
    minute = 0;
    second = 0;
  } else if (unit == ChronoUnit.HALF_DAYS) {
    if (hour >= 12) {
      hour = 12;
    } else {
      hour = 0;
    }
    minute = 0;
    second = 0;
  } else if (unit == ChronoUnit.HOURS) {
    minute = 0;
    second = 0;
  } else if (unit == ChronoUnit.MINUTES) {
    second = 0;
  }
  return PackedLocalTime.create(hour, minute, second, milli);
}
 
Example 5
Source File: TCKPeriod.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 6
Source File: TCKPeriod.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 7
Source File: PackedLocalTime.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
public static int truncatedTo(TemporalUnit unit, int packedTime) {
  if (unit == ChronoUnit.NANOS || unit == ChronoUnit.MILLIS) {
    return packedTime;
  }
  Duration unitDur = unit.getDuration();
  if (unitDur.getSeconds() > SECONDS_PER_DAY) {
    throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation");
  }

  int hour = PackedLocalTime.getHour(packedTime);
  int minute = PackedLocalTime.getMinute(packedTime);
  int second = PackedLocalTime.getSecond(packedTime);
  int milli = 0;

  if (unit == ChronoUnit.DAYS) {
    hour = 0;
    minute = 0;
    second = 0;
  } else if (unit == ChronoUnit.HALF_DAYS) {
    if (hour >= 12) {
      hour = 12;
    } else {
      hour = 0;
    }
    minute = 0;
    second = 0;
  } else if (unit == ChronoUnit.HOURS) {
    minute = 0;
    second = 0;
  } else if (unit == ChronoUnit.MINUTES) {
    second = 0;
  }
  return PackedLocalTime.create(hour, minute, second, milli);
}
 
Example 8
Source File: TCKPeriod.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 9
Source File: TCKPeriod.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 10
Source File: TCKPeriod.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 11
Source File: TCKPeriod.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 12
Source File: TCKPeriod.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 13
Source File: TCKPeriod.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 14
Source File: TCKPeriod.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 15
Source File: TCKPeriod.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 16
Source File: TCKPeriod.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 17
Source File: TCKPeriod.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="BadTemporalUnit")
Object[][] data_badTemporalUnit() {
    return new Object[][] {
        {ChronoUnit.MICROS},
        {ChronoUnit.MILLIS},
        {ChronoUnit.HALF_DAYS},
        {ChronoUnit.DECADES},
        {ChronoUnit.CENTURIES},
        {ChronoUnit.MILLENNIA},
    };
}
 
Example 18
Source File: ChronoConverterUtilsImpl.java    From IridiumApplicationTesting with MIT License 4 votes vote down vote up
@Override
public ChronoUnit fromString(@NotNull final String input) {
	checkArgument(StringUtils.isNotBlank(input));

	if ("Nanos".equalsIgnoreCase(input) || "Nano".equalsIgnoreCase(input)) {
		return ChronoUnit.NANOS;
	}

	if ("Micros".equalsIgnoreCase(input) || "Micro".equalsIgnoreCase(input)) {
		return ChronoUnit.MICROS;
	}

	if ("Millis".equalsIgnoreCase(input) || "Milli".equalsIgnoreCase(input)) {
		return ChronoUnit.MILLIS;
	}

	if ("Seconds".equalsIgnoreCase(input) || "Second".equalsIgnoreCase(input)) {
		return ChronoUnit.SECONDS;
	}

	if ("Minutes".equalsIgnoreCase(input) || "Minute".equalsIgnoreCase(input)) {
		return ChronoUnit.MINUTES;
	}

	if ("Hours".equalsIgnoreCase(input) || "Hour".equalsIgnoreCase(input)) {
		return ChronoUnit.HOURS;
	}

	if ("HalfDays".equalsIgnoreCase(input) || "HalfDay".equalsIgnoreCase(input)) {
		return ChronoUnit.HALF_DAYS;
	}

	if ("Days".equalsIgnoreCase(input) || "Day".equalsIgnoreCase(input)) {
		return ChronoUnit.DAYS;
	}

	if ("Weeks".equalsIgnoreCase(input) || "Week".equalsIgnoreCase(input)) {
		return ChronoUnit.WEEKS;
	}

	if ("Months".equalsIgnoreCase(input) || "Month".equalsIgnoreCase(input)) {
		return ChronoUnit.MONTHS;
	}

	if ("Years".equalsIgnoreCase(input) || "Year".equalsIgnoreCase(input)) {
		return ChronoUnit.YEARS;
	}

	if ("Decades".equalsIgnoreCase(input) || "Decade".equalsIgnoreCase(input)) {
		return ChronoUnit.DECADES;
	}

	if ("Centuries".equalsIgnoreCase(input) || "Century".equalsIgnoreCase(input)) {
		return ChronoUnit.CENTURIES;
	}

	if ("Millennia".equalsIgnoreCase(input)) {
		return ChronoUnit.MILLENNIA;
	}

	if ("Eras".equalsIgnoreCase(input) || "Era".equalsIgnoreCase(input)) {
		return ChronoUnit.ERAS;
	}

	if ("Forever".equalsIgnoreCase(input)) {
		return ChronoUnit.FOREVER;
	}

	throw new InvalidInputException(input + " is not a valid ChronoUnit");
}
 
Example 19
Source File: TimeIntervalTest.java    From influxdb-client-java with MIT License 3 votes vote down vote up
@Test
void halfDays() {

    TimeInterval interval = new TimeInterval(7L, ChronoUnit.HALF_DAYS);

    Assertions.assertThat(interval.toString()).isEqualTo("84h");
}