Ejemplo n.º 1
0
  public static long toLong(Object obj, final long longDefault) {

    if (obj instanceof Long) {
      return (Long) obj;
    }

    if (obj instanceof Number) {
      return ((Number) obj).longValue();
    } else if (obj instanceof CharSequence) {
      String str = Str.toString(obj);
      if (Dates.isJsonDate(str)) {
        return Dates.fromJsonDate(str).getTime();
      }

      try {
        return StringScanner.parseLong(str);
      } catch (Exception ex) {
        return longDefault;
      }
    } else if (obj instanceof Date) {
      return ((Date) obj).getTime();
    } else {
      return toInt(obj);
    }
  }
Ejemplo n.º 2
0
  public static Date toEuroDate(String string) {

    String[] split = StringScanner.splitByChars(string, new char[] {'.', '\\', '/', ':'});

    if (split.length == 3) {
      return Dates.getEuroDate(toInt(split[0]), toInt(split[1]), toInt(split[2]));
    } else if (split.length >= 6) {
      return Dates.getEuroDate(
          toInt(split[0]),
          toInt(split[1]),
          toInt(split[2]),
          toInt(split[3]),
          toInt(split[4]),
          toInt(split[5]));
    } else {
      die(String.format("Not able to parse %s into a Euro date", string));
      return null;
    }
  }
Ejemplo n.º 3
0
  public static Date toDate(Object object) {

    if (object instanceof Date) {
      return (Date) object;
    } else if (object instanceof Value) {
      return ((Value) object).dateValue();
    } else if (object instanceof Calendar) {
      return ((Calendar) object).getTime();
    } else if (object instanceof Long) {
      return new Date((long) object);
    } else if (object instanceof String) {
      String val = (String) object;
      char[] chars = FastStringUtils.toCharArray(val);
      if (Dates.isISO8601QuickCheck(chars)) {
        return Dates.fromISO8601DateLoose(chars);
      } else {
        return toDateUS(val);
      }
    }
    return null;
  }