class Time {

  public static long toMilliseconds(long ts) throws IllegalArgumentException {
    /*
     * Sanity check just in case event time format is different from user specified format.
     */
    int length = (int) (Math.log10(ts) + 1);
    switch (length) {
      case 10: // seconds
        return ts * 1000;
      case 13: // milliseconds
        return ts;
      case 16: // microseconds
        return ts / 1000;
      case 19: // nanoseconds
        return ts / 1000000;
      default:
        throw new IllegalArgumentException("Timestamp is out of valid range");
    }
  }

}