Package jodd.datetime

Examples of jodd.datetime.JDateTime


    assertEquals(true, Convert.toBooleanValue("true", false));
    assertEquals(false, Convert.toBooleanValue(null, false));
    assertEquals(true, Convert.toBooleanValue("true"));
    assertEquals(false, Convert.toBooleanValue(null));

    assertNotNull(Convert.toCalendar((new JDateTime())));

    assertEquals(Character.valueOf('A'), Convert.toCharacter("A"));
    assertEquals('A', Convert.toCharValue("A", ' '));
    assertEquals('A', Convert.toCharValue("A"));

    assertEquals(Integer.class, Convert.toClass("java.lang.Integer"));

    assertEquals(Integer.class, Convert.toClassArray("java.lang.Integer")[0]);
    assertEquals(1, Convert.toClassArray("java.lang.Integer").length);

    assertNotNull(Convert.toDate(new JDateTime()));

    assertEquals(173, Convert.toIntValue("173"));
    assertEquals(173, Convert.toLongValue("173"));
    assertEquals(173, Convert.toShortValue("173"));
    assertEquals(17, Convert.toByteValue("17"));
View Full Code Here


    assertEquals(defaultBigInteger, Convert.toBigInteger(null, defaultBigInteger));

    String defaultString = "123qweasdzxc";
    assertEquals(defaultString, Convert.toString(null, defaultString));

    JDateTime defaultJDateTime = new JDateTime(2010, 4, 20);
    assertEquals(defaultJDateTime, Convert.toJDateTime(null, defaultJDateTime));

    Date defaultDate = defaultJDateTime.convertToDate();
    assertEquals(defaultDate, Convert.toDate(null, defaultDate));

    Calendar defaultCalendar = defaultJDateTime.convertToCalendar();
    assertEquals(defaultCalendar, Convert.toCalendar(null, defaultCalendar));

    assertEquals(Boolean.TRUE, Convert.toBoolean(null, Boolean.TRUE));
    assertEquals(Byte.valueOf((byte) 123), Convert.toByte(null, Byte.valueOf((byte) 123)));
    assertEquals(Character.valueOf('A'), Convert.toCharacter(null, Character.valueOf('A')));
View Full Code Here

    assertEquals(time, sqltime.getTime());
  }

  @Test
  public void testJDateTime2Timestamp() {
    JDateTime jdt = new JDateTime(time);
    Time sqltime = sqlTimeConverter.convert(jdt);
    assertEquals(time, sqltime.getTime());
  }
View Full Code Here

    assertEquals(time, date.getTime());
  }

  @Test
  public void testJDateTime2SqlDate() {
    JDateTime jdt = new JDateTime(time);
    Date date = sqlDateConverter.convert(jdt);
    assertEquals(time, date.getTime());
  }
View Full Code Here

    assertEquals(time, date.getTime());
  }

  @Test
  public void testJDateTime2Date() {
    JDateTime jdt = new JDateTime(time);
    Date date = dateConverter.convert(jdt);
    assertEquals(time, date.getTime());
  }
View Full Code Here

    String stringValue = value.toString().trim();

    if (StringUtil.containsOnlyDigits(stringValue) == false) {
      // try to parse default string format
      JDateTime jdt = new JDateTime(stringValue, JDateTime.DEFAULT_FORMAT);
      return jdt.convertToDate();
    }

    try {
      long milliseconds = Long.parseLong(stringValue);
      return new Date(milliseconds);
View Full Code Here

    if (value instanceof JDateTime) {
      return (JDateTime) value;
    }
    if (value instanceof Calendar) {
      return new JDateTime((Calendar)value);
    }
    if (value instanceof Date) {
      return new JDateTime((Date) value);
    }

    if (value instanceof Number) {
      return new JDateTime(((Number) value).longValue());
    }

    if (value instanceof JulianDateStamp) {
      return new JDateTime((JulianDateStamp) value);
    }
    if (value instanceof DateTimeStamp) {
      return new JDateTime((DateTimeStamp) value);
    }

    String stringValue = value.toString().trim();

    if (StringUtil.containsOnlyDigits(stringValue) == false) {
      return new JDateTime(stringValue, JDateTime.DEFAULT_FORMAT);
    }
    try {
      long milliseconds = Long.parseLong(stringValue);
      return new JDateTime(milliseconds);
    } catch (NumberFormatException nfex) {
      throw new TypeConversionException(value, nfex);
    }
  }
View Full Code Here

    assertEquals(time, calendar.getTimeInMillis());
  }

  @Test
  public void testJDateTime2Calendar() {
    JDateTime jdt = new JDateTime(time);
    Calendar calendar = calendarConverter.convert(jdt);
    assertEquals(time, calendar.getTimeInMillis());
  }
View Full Code Here

    assertEquals(time, calendar.getTimeInMillis());
  }

  @Test
  public void testCalendarDate() {
    JDateTime jdt = new JDateTime();

    CalendarConverter calendarConverter = new CalendarConverter();
    Calendar gc = calendarConverter.convert(jdt);
    DateFormat df = new SimpleDateFormat();
    assertEquals(df.format(gc.getTime()), df.format(Convert.toDate(jdt)));
View Full Code Here

TOP

Related Classes of jodd.datetime.JDateTime

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.