Search in sources :

Example 1 with DateFormatOptions

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);
}
Also used : CalendarDate(com.squarespace.cldrengine.api.CalendarDate) Variable(com.squarespace.template.Variable) DateFormatOptions(com.squarespace.cldrengine.api.DateFormatOptions) CLDR(com.squarespace.cldrengine.CLDR)

Example 2 with DateFormatOptions

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);
}
Also used : CalendarDate(com.squarespace.cldrengine.api.CalendarDate) DateFormatOptions(com.squarespace.cldrengine.api.DateFormatOptions) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 3 with DateFormatOptions

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;
}
Also used : DateFormatOptions(com.squarespace.cldrengine.api.DateFormatOptions)

Example 4 with DateFormatOptions

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);
}
Also used : DateFormatOptions(com.squarespace.cldrengine.api.DateFormatOptions)

Aggregations

DateFormatOptions (com.squarespace.cldrengine.api.DateFormatOptions)4 CalendarDate (com.squarespace.cldrengine.api.CalendarDate)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 CLDR (com.squarespace.cldrengine.CLDR)1 Variable (com.squarespace.template.Variable)1