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

Method readTimestamp

base/src/main/java/net/time4j/Moment.java:2294–2359  ·  view source on GitHub ↗

Deserialisierungsmethode. @param in input stream @param positiveLS positive leap second indicated? @return deserialized instance @throws IOException in case of I/O-errors

(
        DataInput in,
        boolean positiveLS,
        boolean hasNanos
    )

Source from the content-addressed store, hash-verified

2292 * @throws IOException in case of I/O-errors
2293 */
2294 static Moment readTimestamp(
2295 DataInput in,
2296 boolean positiveLS,
2297 boolean hasNanos
2298 ) throws IOException {
2299
2300 long unixTime = in.readLong();
2301 int nano = (hasNanos ? in.readInt() : 0);
2302
2303 if (unixTime == 0) {
2304 if (positiveLS) {
2305 throw new InvalidObjectException(
2306 "UTC epoch is no leap second.");
2307 } else if (nano == 0) {
2308 return UNIX_EPOCH;
2309 }
2310 }
2311
2312 if (
2313 (unixTime == MIN_LIMIT)
2314 && (nano == 0)
2315 ) {
2316 if (positiveLS) {
2317 throw new InvalidObjectException("Minimum is no leap second.");
2318 }
2319 return MIN;
2320 } else if (
2321 (unixTime == MAX_LIMIT)
2322 && (nano == MRD - 1)
2323 ) {
2324 if (positiveLS) {
2325 throw new InvalidObjectException("Maximum is no leap second.");
2326 }
2327 return MAX;
2328 } else {
2329 checkFraction(nano);
2330 }
2331
2332 if (positiveLS) {
2333 LeapSeconds ls = LeapSeconds.getInstance();
2334 if (
2335 !ls.isEnabled() // keep LS-state when propagating to next vm
2336 || ls.isPositiveLS(ls.enhance(unixTime) + 1)
2337 ) {
2338 nano |= POSITIVE_LEAP_MASK;
2339 } else {
2340 long packed = GregorianMath.toPackedDate(unixTime);
2341 int month = GregorianMath.readMonth(packed);
2342 int day = GregorianMath.readDayOfMonth(packed);
2343 throw new InvalidObjectException(
2344 "Not registered as leap second event: "
2345 + GregorianMath.readYear(packed)
2346 + "-"
2347 + ((month < 10) ? "0" : "")
2348 + month
2349 + ((day < 10) ? "0" : "")
2350 + day
2351 + " [Please check leap second configurations "

Callers 1

readMomentMethod · 0.95

Calls 9

checkFractionMethod · 0.95
getInstanceMethod · 0.95
isEnabledMethod · 0.95
isPositiveLSMethod · 0.95
enhanceMethod · 0.95
toPackedDateMethod · 0.95
readMonthMethod · 0.95
readDayOfMonthMethod · 0.95
readYearMethod · 0.95

Tested by

no test coverage detected