Search in sources :

Example 16 with ClockTime

use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.

the class TestTMLJson method testClockTime.

@Test
public void testClockTime() throws Exception {
    Navajo n = NavajoFactory.getInstance().createNavajo(getClass().getResourceAsStream("message2.xml"));
    JSONTML json = JSONTMLFactory.getInstance();
    Property prop = NavajoFactory.getInstance().createProperty(n, "clockTimeProp", "", "", "");
    prop.setAnyValue(new ClockTime("11:12:12"));
    n.getMessage("SimpleMessage").addProperty(prop);
    Writer sw = new StringWriter();
    json.format(n, sw, true);
    String result = sw.toString();
    Assert.assertEquals("{\n  \"clockTimeProp\" : \"11:12:00\"\n}", result);
}
Also used : StringWriter(java.io.StringWriter) JSONTML(com.dexels.navajo.document.json.JSONTML) Navajo(com.dexels.navajo.document.Navajo) ClockTime(com.dexels.navajo.document.types.ClockTime) Property(com.dexels.navajo.document.Property) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 17 with ClockTime

use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.

the class DateAdd method evaluate.

@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    if (getOperands().size() > 2) {
        java.util.Date datum = (java.util.Date) this.getOperands().get(0);
        Integer arg = (Integer) this.getOperands().get(1);
        String field = (String) this.getOperands().get(2);
        Calendar cal = Calendar.getInstance();
        cal.setTime(datum);
        if (field.equals("YEAR")) {
            cal.add(Calendar.YEAR, arg.intValue());
        } else if (field.equals("MONTH")) {
            cal.add(Calendar.MONTH, arg.intValue());
        } else if (field.equals("DAY")) {
            cal.add(Calendar.DAY_OF_YEAR, arg.intValue());
        } else if (field.equals("WEEK")) {
            cal.add(Calendar.WEEK_OF_YEAR, arg.intValue());
        } else if (field.equals("HOUR")) {
            cal.add(Calendar.HOUR_OF_DAY, arg.intValue());
        } else if (field.equals("MINUTE")) {
            cal.add(Calendar.MINUTE, arg.intValue());
        } else if (field.equals("SECOND")) {
            cal.add(Calendar.SECOND, arg.intValue());
        }
        return cal.getTime();
    }
    java.util.Date datum = (java.util.Date) this.getOperands().get(0);
    ClockTime arg = (ClockTime) this.getOperands().get(1);
    Calendar cal = Calendar.getInstance();
    cal.setTime(datum);
    cal.set(Calendar.HOUR_OF_DAY, arg.getHours());
    cal.set(Calendar.MINUTE, arg.getMinutes());
    cal.set(Calendar.SECOND, arg.getSeconds());
    return cal.getTime();
}
Also used : Calendar(java.util.Calendar) ClockTime(com.dexels.navajo.document.types.ClockTime)

Example 18 with ClockTime

use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.

the class FormatDate method evaluate.

@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    if (this.getOperands().size() < 2 || this.getOperands().size() > 3)
        throw new TMLExpressionException(this.usage());
    if (getOperands().get(0) == null) {
        return "";
    }
    java.util.Date date = null;
    if (getOperands().get(0) instanceof ClockTime) {
        date = ((ClockTime) getOperands().get(0)).dateValue();
    } else if (getOperands().get(0) instanceof java.util.Date) {
        date = (java.util.Date) getOperands().get(0);
    } else {
        throw new TMLExpressionException(this, "Type mismatch");
    }
    String format = (String) this.getOperands().get(1);
    if (format == null)
        throw new TMLExpressionException("FormatDate: format cannot be null");
    java.text.SimpleDateFormat formatter = null;
    if (this.getOperands().size() > 2) {
        final String loc = (String) this.getOperands().get(2);
        if (loc != null && loc.length() > 0) {
            final Locale l = new Locale(loc);
            formatter = new java.text.SimpleDateFormat(format, l);
        }
    } else if (getAccess() != null && getAccess().getInDoc() != null) {
        String localeheader = getAccess().getInDoc().getHeader().getHeaderAttribute("locale");
        if (localeheader != null) {
            final Locale l = new Locale(localeheader);
            formatter = new java.text.SimpleDateFormat(format, l);
        }
    }
    if (formatter == null) {
        // fallback
        formatter = new java.text.SimpleDateFormat(format);
    }
    return formatter.format(date);
}
Also used : Locale(java.util.Locale) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) ClockTime(com.dexels.navajo.document.types.ClockTime)

Example 19 with ClockTime

use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.

the class ToClockTime method main.

public static void main(String[] args) throws Exception {
    // Tests.
    ToClockTime cct = new ToClockTime();
    cct.reset();
    cct.insertStringOperand("12");
    System.out.println("cct = " + cct.evaluate());
    String expr = "ToClockTime('09:00') + ToClockTime('10')";
    Operand o = Expression.evaluate(expr, null);
    System.out.println("9:00 > 10:00 ? " + o.value + ", ToClockTime('25:88') = " + new ClockTime("25:88").toString());
    expr = "ToClockTime('9') >= ToClockTime('9')";
    Operand o2 = Expression.evaluate(expr, null);
    System.out.println("9:00 >= 9:00 ? " + o2.value);
    expr = "ToClockTime('9') < ToClockTime('12')";
    Operand o3 = Expression.evaluate(expr, null);
    System.out.println("9:00 < 12:00 ? " + o3.value);
}
Also used : Operand(com.dexels.navajo.document.Operand) ClockTime(com.dexels.navajo.document.types.ClockTime)

Example 20 with ClockTime

use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.

the class DateAppendClockTime method testValidArguements.

@Test
public void testValidArguements() throws Exception {
    Date date = new Date();
    ClockTime cTime = new ClockTime("11:28");
    System.out.println(" ------ Running Valid Parameters case ------ ");
    System.out.println("Sending Date :: " + date);
    System.out.println("Sending ClockTime :: " + cTime);
    da.reset();
    da.insertDateOperand(date);
    da.insertClockTimeOperand(cTime);
    System.out.println(da.evaluate());
    Object o = da.evaluate();
    assertEquals(o.getClass(), java.util.Date.class);
}
Also used : ClockTime(com.dexels.navajo.document.types.ClockTime) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ClockTime (com.dexels.navajo.document.types.ClockTime)24 Date (java.util.Date)14 Test (org.junit.Test)8 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)7 Money (com.dexels.navajo.document.types.Money)6 Percentage (com.dexels.navajo.document.types.Percentage)6 StopwatchTime (com.dexels.navajo.document.types.StopwatchTime)5 Calendar (java.util.Calendar)5 Navajo (com.dexels.navajo.document.Navajo)4 Property (com.dexels.navajo.document.Property)4 Binary (com.dexels.navajo.document.types.Binary)4 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)3 Message (com.dexels.navajo.document.Message)3 Date (java.sql.Date)3 SQLException (java.sql.SQLException)3 Timestamp (java.sql.Timestamp)3 NavajoException (com.dexels.navajo.document.NavajoException)2 Operand (com.dexels.navajo.document.Operand)2 DatePattern (com.dexels.navajo.document.types.DatePattern)2 NavajoType (com.dexels.navajo.document.types.NavajoType)2