MCPcopy Create free account
hub / github.com/MenoData/Time4J / of

Method of

base/src/main/java/net/time4j/MachineTime.java:191–212  ·  view source on GitHub ↗
(
        long amount,
        TimeUnit unit
    )

Source from the content-addressed store, hash-verified

189 * @since 2.0
190 */
191 public static MachineTime<TimeUnit> of(
192 long amount,
193 TimeUnit unit
194 ) {
195
196 if (unit.compareTo(TimeUnit.SECONDS) >= 0) {
197 long secs =
198 Math.multiplyExact(
199 amount,
200 TimeUnit.SECONDS.convert(1, unit));
201 return ofPosixUnits(secs, 0);
202 }
203
204 long total =
205 Math.multiplyExact(
206 amount,
207 TimeUnit.NANOSECONDS.convert(1, unit));
208 long secs = Math.floorDiv(total, MRD);
209 int fraction = (int) Math.floorMod(total, MRD);
210 return ofPosixUnits(secs, fraction);
211
212 }
213
214 /**
215 * <p>Creates a machine time duration on the UTC scale. </p>

Callers 15

isShorterThanMethod · 0.95
ofDayUnitMethod · 0.95
ofHourUnitMethod · 0.95
ofMinuteUnitMethod · 0.95
ofMillisecondUnitMethod · 0.95
ofMicrosecondUnitMethod · 0.95
isEmptyMethod · 0.95
isPositiveMethod · 0.95
isNegativeMethod · 0.95
containsMethod · 0.95
format1Method · 0.95

Calls 7

ofPosixUnitsMethod · 0.95
ofSIUnitsMethod · 0.95
floorDivMethod · 0.80
floorModMethod · 0.80
nameMethod · 0.65
compareToMethod · 0.45
convertMethod · 0.45

Tested by 15

isShorterThanMethod · 0.76
ofDayUnitMethod · 0.76
ofHourUnitMethod · 0.76
ofMinuteUnitMethod · 0.76
ofMillisecondUnitMethod · 0.76
ofMicrosecondUnitMethod · 0.76
isEmptyMethod · 0.76
isPositiveMethod · 0.76
isNegativeMethod · 0.76
containsMethod · 0.76
format1Method · 0.76