use of com.squarespace.cldrengine.api.DateFormatOptions 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.api.DateFormatOptions in project template-compiler by Squarespace.
the class MessageFormats method datetime.
/**
* Datetime message formatter.
*/
private String datetime(List<Object> args, List<String> options) {
if (args.isEmpty()) {
return "";
}
JsonNode node = (JsonNode) args.get(0);
if (node == null) {
return "";
}
long epoch = node.asLong();
CalendarDate date = cldr.Calendars.toGregorianDate(epoch, zoneId);
DateFormatOptions opts = OptionParsers.datetime(options);
return cldr.Calendars.formatDate(date, opts);
}
use of com.squarespace.cldrengine.api.DateFormatOptions in project template-compiler by Squarespace.
the class OptionParsers method datetime.
public static DateFormatOptions datetime(List<String> args) {
DateFormatOptions options = DateFormatOptions.build();
parse(args, options, OptionParsers::datetimeOption);
return options;
}
use of com.squarespace.cldrengine.api.DateFormatOptions in project template-compiler by Squarespace.
the class DateTimeFormatter method validateArgs.
@Override
public void validateArgs(Arguments args) throws ArgumentsException {
DateFormatOptions options = OptionParsers.datetime(args);
args.setOpaque(options);
}
Aggregations