Change iso timestamp to long long.

@param isoTimestamp the iso timestamp
@param zoneId       the zone id
@return the long
353560
public static long changeIsoTimestampToLong(String isoTimestamp,
            String zoneId) {
        try {
            return LocalDateTime.parse(isoTimestamp).atZone(getZoneId(zoneId))
                    .toInstant().toEpochMilli();
        } catch (Exception e) {
            isoTimestamp = changeZTo0000(isoTimestamp);
            return changeTimestampToLong(getTimeFormat(isoTimestamp),
                    isoTimestamp, zoneId);
        }
    }
1287899
private long updateBaseTime(final long timestamp) {
    // We force the starting timestamp to be on a MAX_TIMESPAN boundary
    // so that all TSDs create rows with the same base time. Otherwise
    // we'd need to coordinate TSDs to avoid creating rows that cover
    // overlapping time periods.
    final long base_time = timestamp - (timestamp % Const.MAX_TIMESPAN);
    // Clone the row key since we're going to change it. We must clone it
    // because the HBase client may still hold a reference to it in its
    // internal datastructures.
    row = Arrays.copyOf(row, row.length);
    Bytes.setInt(row, (int) base_time, Const.SALT_WIDTH() + tsdb.metrics.width());
    RowKey.prefixKeyWithSalt(row); // in case the timestamp will be involved in
                                   // salting later
    tsdb.scheduleForCompaction(row, (int) base_time);
    return base_time;
  }
486077
private long readTimeStamp(byte[] buffer, int offset) {
        long seconds = read32(buffer, offset);
        long fraction = read32(buffer, offset + 4);
        return ((seconds - OFFSET_1900_TO_1970) * 1000) + ((fraction * 1000L) / 0x100000000L);
    }
1172743
public DateTimeZone toDateTimeZone(String id, boolean outputID) {
        if (id == null) {
            throw new IllegalArgumentException();
        }

        // Discover where all the transitions occur and store the results in
        // these lists.
        ArrayList<Transition> transitions = new ArrayList<Transition>();

        // Tail zone picks up remaining transitions in the form of an endless
        // DST cycle.
        DSTZone tailZone = null;

        long millis = Long.MIN_VALUE;
        int saveMillis = 0;
            
        int ruleSetCount = iRuleSets.size();
        for (int i=0; i<ruleSetCount; i++) {
            RuleSet rs = iRuleSets.get(i);
            Transition next = rs.firstTransition(millis);
            if (next == null) {
                continue;
            }
            addTransition(transitions, next);
            millis = next.getMillis();
            saveMillis = next.getSaveMillis();

            // Copy it since we're going to destroy it.
            rs = new RuleSet(rs);

            while ((next = rs.nextTransition(millis, saveMillis)) != null) {
                if (addTransition(transitions, next) && tailZone != null) {
                    // Got the extra transition before DSTZone.
                    break;
                }
                millis = next.getMillis();
                saveMillis = next.getSaveMillis();
                if (tailZone == null && i == ruleSetCount - 1) {
                    tailZone = rs.buildTailZone(id);
                    // If tailZone is not null, don't break out of main loop until
                    // at least one more transition is calculated. This ensures a
                    // correct 'seam' to the DSTZone.
                }
            }

            millis = rs.getUpperLimit(saveMillis);
        }

        // Check if a simpler zone implementation can be returned.
        if (transitions.size() == 0) {
            if (tailZone != null) {
                // This shouldn't happen, but handle just in case.
                return tailZone;
            }
            return buildFixedZone(id, "UTC", 0, 0);
        }
        if (transitions.size() == 1 && tailZone == null) {
            Transition tr = transitions.get(0);
            return buildFixedZone(id, tr.getNameKey(),
                                  tr.getWallOffset(), tr.getStandardOffset());
        }

        PrecalculatedZone zone = PrecalculatedZone.create(id, outputID, transitions, tailZone);
        if (zone.isCachable()) {
            return CachedDateTimeZone.forZone(zone);
        }
        return zone;
    }
341272
public void setTime(final long millis) {
        int millisOfDay = ISOChronology.getInstanceUTC().millisOfDay().get(millis);
        setMillis(getChronology().millisOfDay().set(getMillis(), millisOfDay));
    }
1333608
public long fromISO8601Date(String isoDt, DateTimeZone dtz) throws IllegalArgumentException {
		LocalDate lDate = FORMATTER__ISO_DATE.parseLocalDate(isoDt);
		return lDate.toDateTimeAtStartOfDay(dtz).getMillis(); // avoids bizarre situations like 1969-06-01 in IT (there was no 00:00)
	}
1204903
public static long extractTimestamp128(BigInteger id128) {
        BigInteger result = id128.shiftRight((int) SHIFT_TIMESTAMP_128);
        return result.longValue();
    }
203309
public static TransitionHistory load(ZoneId zoneId) {

        try {
            ZoneRules zoneRules = zoneId.getRules();
            ZonalOffset initialOffset = ZonalOffset.ofTotalSeconds(zoneRules.getOffset(Instant.MIN).getTotalSeconds());
            List<ZonalTransition> transitions = new ArrayList<>();
            List<DaylightSavingRule> rules = new ArrayList<>();

            for (ZoneOffsetTransition zot : zoneRules.getTransitions()) {
                Instant instant = zot.getInstant();
                long posixTime = instant.getEpochSecond();
                int previousOffset = zot.getOffsetBefore().getTotalSeconds();
                int totalOffset = zot.getOffsetAfter().getTotalSeconds();
                int dst = Math.toIntExact(zoneRules.getDaylightSavings(instant).getSeconds());
                transitions.add(new ZonalTransition(posixTime, previousOffset, totalOffset, dst));
            }

            for (ZoneOffsetTransitionRule zotr : zoneRules.getTransitionRules()) {
                DaylightSavingRule rule;

                int dom = zotr.getDayOfMonthIndicator(); // -28 bis +31 (ohne 0)
                DayOfWeek dayOfWeek = zotr.getDayOfWeek();

                Month month = Month.valueOf(zotr.getMonth().getValue());

                PlainTime timeOfDay = (
                    zotr.isMidnightEndOfDay()
                        ? PlainTime.midnightAtEndOfDay()
                        : TemporalType.LOCAL_TIME.translate(zotr.getLocalTime()));

                OffsetIndicator indicator;
                switch (zotr.getTimeDefinition()) {
                    case STANDARD:
                        indicator = OffsetIndicator.STANDARD_TIME;
                        break;
                    case UTC:
                        indicator = OffsetIndicator.UTC_TIME;
                        break;
                    case WALL:
                        indicator = OffsetIndicator.WALL_TIME;
                        break;
                    default:
                        throw new UnsupportedOperationException(zotr.getTimeDefinition().name());
                }

                int dst = (zotr.getOffsetAfter().getTotalSeconds() - zotr.getStandardOffset().getTotalSeconds());

                if (dayOfWeek == null) {
                    rule = GregorianTimezoneRule.ofFixedDay(month, dom, timeOfDay, indicator, dst);
                } else {
                    Weekday wd = Weekday.valueOf(dayOfWeek.getValue());
                    if (dom == -1) {
                        rule = GregorianTimezoneRule.ofLastWeekday(month, wd, timeOfDay, indicator, dst);
                    } else if (dom < 0) {
                        rule = new NegativeDayOfMonthPattern(month, dom, wd, timeOfDay, indicator, dst);
                    } else {
                        rule = GregorianTimezoneRule.ofWeekdayAfterDate(month, dom, wd, timeOfDay, indicator, dst);
                    }
                }

                rules.add(rule);
            }

            return TransitionModel.of(initialOffset, transitions, rules);

        } catch (DateTimeException ex) {
            throw new IllegalArgumentException(ex);
        }

    }
695750
public Timestamp getInternalTimestamp(ColumnInformation columnInfo, Calendar userCalendar,
      TimeZone timeZone) throws SQLException {
    if (lastValueWasNull()) {
      return null;
    }
    if (length == 0) {
      lastValueNull |= BIT_LAST_FIELD_NULL;
      return null;
    }

    int year = 1970;
    int month = 0;
    int day = 0;
    int hour = 0;
    int minutes = 0;
    int seconds = 0;
    int microseconds = 0;

    switch (columnInfo.getColumnType()) {
      case TIME:
        Calendar calendar = userCalendar != null ? userCalendar : Calendar.getInstance();

        boolean negate = false;
        if (length > 0) {
          negate = (buf[pos] & 0xff) == 0x01;
        }
        if (length > 4) {
          day = ((buf[pos + 1] & 0xff)
              + ((buf[pos + 2] & 0xff) << 8)
              + ((buf[pos + 3] & 0xff) << 16)
              + ((buf[pos + 4] & 0xff) << 24));
        }
        if (length > 7) {
          hour = buf[pos + 5];
          minutes = buf[pos + 6];
          seconds = buf[pos + 7];
        }

        if (length > 8) {
          microseconds = ((buf[pos + 8] & 0xff)
              + ((buf[pos + 9] & 0xff) << 8)
              + ((buf[pos + 10] & 0xff) << 16)
              + ((buf[pos + 11] & 0xff) << 24));
        }
        year = 1970;
        month = 1;
        day = ((negate ? -1 : 1) * day) + 1;
        hour = (negate ? -1 : 1) * hour;
        break;

      case STRING:
      case VARSTRING:
        String rawValue = new String(buf, pos, length, StandardCharsets.UTF_8);
        if (rawValue.startsWith("0000-00-00 00:00:00")) {
          lastValueNull |= BIT_LAST_ZERO_DATE;
          return null;
        }

        if (rawValue.length() >= 4) {
          year = Integer.parseInt(rawValue.substring(0, 4));
          if (rawValue.length() >= 7) {
            month = Integer.parseInt(rawValue.substring(5, 7));
            if (rawValue.length() >= 10) {
              day = Integer.parseInt(rawValue.substring(8, 10));
              if (rawValue.length() >= 19) {
                hour = Integer.parseInt(rawValue.substring(11, 13));
                minutes = Integer.parseInt(rawValue.substring(14, 16));
                seconds = Integer.parseInt(rawValue.substring(17, 19));
              }
              microseconds = extractNanos(rawValue) / 1000000;
            }
          }
        }
        break;

      default:
        year = ((buf[pos] & 0xff) | (buf[pos + 1] & 0xff) << 8);
        month = buf[pos + 2];
        day = buf[pos + 3];
        if (length > 4) {
          hour = buf[pos + 4];
          minutes = buf[pos + 5];
          seconds = buf[pos + 6];

          if (length > 7) {
            microseconds = ((buf[pos + 7] & 0xff)
                + ((buf[pos + 8] & 0xff) << 8)
                + ((buf[pos + 9] & 0xff) << 16)
                + ((buf[pos + 10] & 0xff) << 24));
          }
        }
    }

    Calendar calendar;
    if (userCalendar != null) {
      calendar = userCalendar;
    } else if (columnInfo.getColumnType().getSqlType() == Types.TIMESTAMP) {
      calendar = Calendar.getInstance(timeZone);
    } else {
      calendar = Calendar.getInstance();
    }

    Timestamp tt;
    synchronized (calendar) {
      calendar.clear();
      calendar.set(year, month - 1, day, hour, minutes, seconds);
      tt = new Timestamp(calendar.getTimeInMillis());
    }
    tt.setNanos(microseconds * 1000);
    return tt;
  }
924268
public OffsetTime getInternalOffsetTime(ColumnInformation columnInfo, TimeZone timeZone)
      throws SQLException {
    if (lastValueWasNull()) {
      return null;
    }
    if (length == 0) {
      lastValueNull |= BIT_LAST_FIELD_NULL;
      return null;
    }

    ZoneId zoneId = timeZone.toZoneId().normalized();
    if (zoneId instanceof ZoneOffset) {
      ZoneOffset zoneOffset = (ZoneOffset) zoneId;

      int day = 0;
      int hour = 0;
      int minutes = 0;
      int seconds = 0;
      int microseconds = 0;

      switch (columnInfo.getColumnType().getSqlType()) {
        case Types.TIMESTAMP:
          int year = ((buf[pos] & 0xff) | (buf[pos + 1] & 0xff) << 8);
          int month = buf[pos + 2];
          day = buf[pos + 3];

          if (length > 4) {
            hour = buf[pos + 4];
            minutes = buf[pos + 5];
            seconds = buf[pos + 6];

            if (length > 7) {
              microseconds = ((buf[pos + 7] & 0xff)
                  + ((buf[pos + 8] & 0xff) << 8)
                  + ((buf[pos + 9] & 0xff) << 16)
                  + ((buf[pos + 10] & 0xff) << 24));
            }
          }

          return ZonedDateTime
              .of(year, month, day, hour, minutes, seconds, microseconds * 1000, zoneOffset)
              .toOffsetDateTime().toOffsetTime();

        case Types.TIME:

          final boolean negate = (buf[pos] & 0xff) == 0x01;

          if (length > 4) {
            day = ((buf[pos + 1] & 0xff)
                + ((buf[pos + 2] & 0xff) << 8)
                + ((buf[pos + 3] & 0xff) << 16)
                + ((buf[pos + 4] & 0xff) << 24));
          }

          if (length > 7) {
            hour = buf[pos + 5];
            minutes = buf[pos + 6];
            seconds = buf[pos + 7];
          }

          if (length > 8) {
            microseconds = ((buf[pos + 8] & 0xff)
                + ((buf[pos + 9] & 0xff) << 8)
                + ((buf[pos + 10] & 0xff) << 16)
                + ((buf[pos + 11] & 0xff) << 24));
          }

          return OffsetTime
              .of((negate ? -1 : 1) * (day * 24 + hour), minutes, seconds, microseconds * 1000,
                  zoneOffset);

        case Types.VARCHAR:
        case Types.LONGVARCHAR:
        case Types.CHAR:
          String raw = new String(buf, pos, length, StandardCharsets.UTF_8);
          try {
            return OffsetTime.parse(raw, DateTimeFormatter.ISO_OFFSET_TIME);
          } catch (DateTimeParseException dateParserEx) {
            throw new SQLException(raw
                + " cannot be parse as OffsetTime (format is \"HH:mm:ss[.S]\" with offset for data type \""
                + columnInfo.getColumnType() + "\")");
          }

        default:
          throw new SQLException("Cannot read " + OffsetTime.class.getName() + " using a "
              + columnInfo.getColumnType().getJavaTypeName() + " field");
      }
    }

    if (options.useLegacyDatetimeCode) {
      //system timezone is not an offset
      throw new SQLException(
          "Cannot return an OffsetTime for a TIME field when default timezone is '" + zoneId
              + "' (only possible for time-zone offset from Greenwich/UTC, such as +02:00)");
    }

    //server timezone is not an offset
    throw new SQLException(
        "Cannot return an OffsetTime for a TIME field when server timezone '" + zoneId
            + "' (only possible for time-zone offset from Greenwich/UTC, such as +02:00)");

  }
397275
static ZonedDateTime getDateFromStringToZoneId(String date, ZoneId zoneId) throws DateTimeParseException {
        ZonedDateTime usDate = ZonedDateTime.parse(date).withZoneSameInstant(ZoneId.of(Constants.SHERDOG_TIME_ZONE));
        return usDate.withZoneSameInstant(zoneId);
    }
436985
public static ZonedDateTime getZonedDataTime(long timestamp,
            String zoneId) {
        return Instant.ofEpochMilli(timestamp).atZone(getZoneId(zoneId));
    }
569784
public static String changeFormatAndTimeZone(String isoTimestamp,
            String toBeTimeFormat, String zoneId) {
        return getTime(changeIsoTimestampToLong(isoTimestamp, zoneId),
                toBeTimeFormat, zoneId);
    }
494625
private String formatTimestamp(String value) {
        try {
            long longValue = Long.parseLong(value);
            return Utils.formatDate(longValue);
        } catch (NumberFormatException e) {
            return "Invalid timestamp: " + value; 
        }
    }
328600
public void setTimeZoneID(String timeZoneId) {
        if (verifyTimeZoneID(timeZoneId)) {
            this.timeZone = TimeZone.getTimeZone(timeZoneId);
        } else {
            throw new IllegalArgumentException(timeZoneId + " is not a valid time zone");
        }

    }
185316
public static long convertToUtc(long millis, String tz)
    {
        long ret = millis;
        if(tz != null && tz.length() > 0)
        {
            DateTime dt = new DateTime(millis, DateTimeZone.forID(tz));
            ret = dt.withZoneRetainFields(DateTimeZone.forID("UTC")).getMillis();
        }
        return ret;
    }
684746
public static String getTime(long epochTimestamp, String timeFormat,
            ZoneId zoneId) {
        return getTime(epochTimestamp, getDateTimeFormatter(timeFormat),
                zoneId);
    }