use of com.squarespace.cldrengine.CLDR in project template-compiler by Squarespace.
the class PluginDateUtilsTest method formatDate.
private String formatDate(String format, long timestamp, String tzId, Locale locale) {
CLDR cldr = CLDR.get(locale);
StringBuilder buf = new StringBuilder();
PluginDateUtils.formatDate(cldr, format, timestamp, tzId, buf);
return buf.toString();
}
use of com.squarespace.cldrengine.CLDR in project template-compiler by Squarespace.
the class MessageFormatsTest method testDecimal.
@Test
public void testDecimal() {
String actual;
CLDR cldr = CLDR.get("en");
MessageFormats formats = new MessageFormats(cldr);
formats.setTimeZone("America/New_York");
String message = "{0 decimal style:short}";
actual = formats.formatter().format(message, args().add(new TextNode("12345.789")));
assertEquals(actual, "12K");
}
use of com.squarespace.cldrengine.CLDR in project template-compiler by Squarespace.
the class MessageFormatsTest method testDateTime.
@Test
public void testDateTime() {
String actual;
CLDR cldr = CLDR.get("en");
MessageFormats formats = new MessageFormats(cldr);
formats.setTimeZone("America/New_York");
String message = "{0 datetime date:long time:medium}";
long epoch = 1582129775000L;
actual = formats.formatter().format(message, args().add(new LongNode(epoch)));
assertEquals(actual, "February 19, 2020 at 11:29:35 AM");
}
use of com.squarespace.cldrengine.CLDR in project template-compiler by Squarespace.
the class DateTimeFormatter method apply.
@Override
public void apply(Context ctx, Arguments args, Variables variables) throws CodeExecuteException {
Variable var = variables.first();
long epoch = var.node().asLong();
String zoneId = PluginDateUtils.getTimeZoneNameFromContext(ctx);
CLDR cldr = ctx.cldr();
DateFormatOptions options = (DateFormatOptions) args.getOpaque();
CalendarDate date = cldr.Calendars.toGregorianDate(epoch, zoneId);
String result = cldr.Calendars.formatDate(date, options);
var.set(result);
}
use of com.squarespace.cldrengine.CLDR in project template-compiler by Squarespace.
the class DecimalFormatter method apply.
@Override
public void apply(Context ctx, Arguments args, Variables variables) throws CodeExecuteException {
Variable var = variables.first();
Decimal number = GeneralUtils.nodeToDecimal(var.node());
if (number == null) {
var.setMissing();
return;
}
CLDR cldr = ctx.cldr();
DecimalFormatOptions opts = (DecimalFormatOptions) args.getOpaque();
String result = cldr.Numbers.formatDecimal(number, opts);
var.set(result);
}
Aggregations