Package org.stjs.javascript

Examples of org.stjs.javascript.Date


  private static final int CALL_METHOD_ARG_COUNT = 3;

  private static Object convertToDate(Object result) {
    Double time = (Double) invoke(result, "callMethod", CALL_METHOD_ARG_COUNT, result, "getTime", null);
    return new Date(time.longValue());
  }
View Full Code Here


  @SuppressWarnings("unchecked")
  private static Object convertScriptObject(Object result) {
    String cls = (String) invoke(result, "getClassName", 0);
    if ("Date".equals(cls)) {
      Double time = (Double) invoke(result, "callMember", CALL_MEMBER_METHOD_ARG_COUNT, "getTime", null);
      return new Date(time.longValue());
    }
    Map<String, Object> js = $map();
    Set<String> ids = (Set<String>) invoke(result, "keySet", 0);
    for (String key : ids) {
      Object value = invoke(result, "get", 1, key);
View Full Code Here

  public Date deserialize(JsonElement elem, Type typeOfT, JsonDeserializationContext context)
      throws JsonParseException {
    if (elem == null) {
      return null;
    }
    return new Date(elem.getAsString());
  }
View Full Code Here

  @Test
  public void testSerializeDate() throws JsonGenerationException, JsonMappingException, IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(STJSModule.getModule());

    String s = mapper.writeValueAsString(new Date(2011, 10, 9, 17, 10, 0, 0));
    assertEquals("\"2011-11-09 17:10:00\"", s);
  }
View Full Code Here

  @Test
  public void testDeserializeDate() throws JsonParseException, JsonMappingException, IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(STJSModule.getModule());

    Date d = mapper.readValue("\"2011-11-09 17:10:00\"", Date.class);
    assertNotNull(d);
    assertEquals(10, (int) d.getMonth());
  }
View Full Code Here

  public void testSerializeDate() throws JsonGenerationException, JsonMappingException, IOException {
    GsonBuilder gsonBuilder = new GsonBuilder();
    GsonAdapters.addAll(gsonBuilder);
    Gson gson = gsonBuilder.create();

    String s = gson.toJson(new Date(2011, 10, 9, 17, 10, 0, 0));
    assertEquals("\"2011-11-09 17:10:00\"", s);
  }
View Full Code Here

  @Test
  public void testDeserializeDate() {
    GsonBuilder gsonBuilder = new GsonBuilder();
    GsonAdapters.addAll(gsonBuilder);
    Gson gson = gsonBuilder.create();
    Date d = gson.fromJson("\"2011-11-09 17:10:00\"", Date.class);
    assertNotNull(d);
    assertEquals(10, (int) d.getMonth());
  }
View Full Code Here

public class JSDateDeserializer extends JsonDeserializer<Date> {

  @Override
  public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    return new Date(jp.getText());
  }
View Full Code Here

public class DateTest {

  @Test
  public void testDate() {
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
    Date d = new Date(2011, 10, 10, 17, 10, 0, 0);
    assertEquals(10, (int) d.getDate());
    assertEquals(17, (int) d.getHours());
    assertEquals(16, (int) d.getUTCHours());

    d.setHours(18);
    assertEquals(18, (int) d.getHours());
    assertEquals(17, (int) d.getUTCHours());

    d.setUTCHours(18);
    assertEquals(19, (int) d.getHours());
    assertEquals(18, (int) d.getUTCHours());
  }
View Full Code Here

  }

  @Test
  public void testInvalidDate() {
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
    Date d = new Date("abc");
    assertTrue(Double.isNaN(d.getDate()));
    assertTrue(Double.isNaN(d.getUTCDate()));
  }
View Full Code Here

TOP

Related Classes of org.stjs.javascript.Date

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.