Search in sources :

Example 1 with DateIntervalFormatOptions

use of com.squarespace.cldrengine.api.DateIntervalFormatOptions in project template-compiler by Squarespace.

the class DateTimeIntervalFormatter method validateArgs.

@Override
public void validateArgs(Arguments args) throws ArgumentsException {
    DateIntervalFormatOptions options = OptionParsers.interval(args);
    args.setOpaque(options);
}
Also used : DateIntervalFormatOptions(com.squarespace.cldrengine.api.DateIntervalFormatOptions)

Example 2 with DateIntervalFormatOptions

use of com.squarespace.cldrengine.api.DateIntervalFormatOptions in project template-compiler by Squarespace.

the class OptionParsers method interval.

public static DateIntervalFormatOptions interval(List<String> args) {
    DateIntervalFormatOptions options = DateIntervalFormatOptions.build();
    parse(args, options, OptionParsers::intervalOption);
    return options;
}
Also used : DateIntervalFormatOptions(com.squarespace.cldrengine.api.DateIntervalFormatOptions)

Example 3 with DateIntervalFormatOptions

use of com.squarespace.cldrengine.api.DateIntervalFormatOptions in project template-compiler by Squarespace.

the class DateTimeIntervalFormatter method apply.

@Override
public void apply(Context ctx, Arguments args, Variables variables) throws CodeExecuteException {
    int count = variables.count();
    if (count < 2) {
        return;
    }
    Variable v1 = variables.get(0);
    Variable v2 = variables.get(1);
    CLDR cldr = ctx.cldr();
    String zoneId = PluginDateUtils.getTimeZoneNameFromContext(ctx);
    CalendarDate start = cldr.Calendars.toGregorianDate(v1.node().asLong(0), zoneId);
    CalendarDate end = cldr.Calendars.toGregorianDate(v2.node().asLong(0), zoneId);
    DateIntervalFormatOptions options = (DateIntervalFormatOptions) args.getOpaque();
    String result = cldr.Calendars.formatDateInterval(start, end, options);
    v1.set(result);
}
Also used : DateIntervalFormatOptions(com.squarespace.cldrengine.api.DateIntervalFormatOptions) CalendarDate(com.squarespace.cldrengine.api.CalendarDate) Variable(com.squarespace.template.Variable) CLDR(com.squarespace.cldrengine.CLDR)

Example 4 with DateIntervalFormatOptions

use of com.squarespace.cldrengine.api.DateIntervalFormatOptions in project template-compiler by Squarespace.

the class MessageFormats method interval.

/**
 * Datetime interval message formatter.
 */
private String interval(List<Object> args, List<String> options) {
    if (args.size() < 2) {
        return "";
    }
    JsonNode v1 = (JsonNode) args.get(0);
    JsonNode v2 = (JsonNode) args.get(1);
    if (v1 == null || v2 == null) {
        return "";
    }
    CalendarDate start = cldr.Calendars.toGregorianDate(v1.asLong(0), zoneId);
    CalendarDate end = cldr.Calendars.toGregorianDate(v2.asLong(0), zoneId);
    DateIntervalFormatOptions opts = OptionParsers.interval(options);
    return cldr.Calendars.formatDateInterval(start, end, opts);
}
Also used : DateIntervalFormatOptions(com.squarespace.cldrengine.api.DateIntervalFormatOptions) CalendarDate(com.squarespace.cldrengine.api.CalendarDate) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

DateIntervalFormatOptions (com.squarespace.cldrengine.api.DateIntervalFormatOptions)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