| 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> |