Search in sources :

Example 6 with MessageFormats

use of com.squarespace.template.MessageFormats in project template-compiler by Squarespace.

the class MessageFormatsTest method testInterval.

@Test
public void testInterval() {
    String actual;
    CLDR cldr = CLDR.get("en");
    MessageFormats formats = new MessageFormats(cldr);
    formats.setTimeZone("America/New_York");
    String message = "{0;1 datetime-interval}";
    long epoch = 1582129775000L;
    long extra = 86400000 + 3600000;
    MessageArgs args = args().add(new LongNode(epoch)).add(new LongNode(epoch + extra));
    actual = formats.formatter().format(message, args);
    assertEquals(actual, "Feb 19 – 20, 2020");
}
Also used : MessageArgs(com.squarespace.cldrengine.api.MessageArgs) CLDR(com.squarespace.cldrengine.CLDR) LongNode(com.fasterxml.jackson.databind.node.LongNode) MessageFormats(com.squarespace.template.MessageFormats) Test(org.testng.annotations.Test)

Example 7 with MessageFormats

use of com.squarespace.template.MessageFormats in project template-compiler by Squarespace.

the class MessageFormatsTest method testCurrency.

@Test
public void testCurrency() {
    String actual;
    CLDR cldr = CLDR.get("en");
    MessageFormats formats = new MessageFormats(cldr);
    formats.setTimeZone("America/New_York");
    String message = "{0 currency style:standard}";
    ObjectNode money = money("12345.789", "USD");
    actual = formats.formatter().format(message, args().add(money));
    assertEquals(actual, "$12,345.79");
    money = newmoney("12345.789", "USD");
    actual = formats.formatter().format(message, args().add(money));
    assertEquals(actual, "$12,345.79");
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CLDR(com.squarespace.cldrengine.CLDR) MessageFormats(com.squarespace.template.MessageFormats) Test(org.testng.annotations.Test)

Aggregations

MessageFormats (com.squarespace.template.MessageFormats)7 CLDR (com.squarespace.cldrengine.CLDR)6 Test (org.testng.annotations.Test)6 LongNode (com.fasterxml.jackson.databind.node.LongNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 TextNode (com.fasterxml.jackson.databind.node.TextNode)2 MessageArgs (com.squarespace.cldrengine.api.MessageArgs)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 DecimalNode (com.fasterxml.jackson.databind.node.DecimalNode)1 GeneralUtils.splitVariable (com.squarespace.template.GeneralUtils.splitVariable)1 Variable (com.squarespace.template.Variable)1 BigDecimal (java.math.BigDecimal)1