Search in sources :

Example 1 with RelativeTimeFormatOptions

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

the class RelativeTimeFormatter method apply.

@Override
public void apply(Context ctx, Arguments args, Variables variables) throws CodeExecuteException {
    int count = variables.count();
    Variable v1 = variables.get(0);
    Long now = ctx.now();
    long s = now == null ? System.currentTimeMillis() : now.longValue();
    long e = v1.node().asLong();
    if (count > 1) {
        s = e;
        e = variables.get(1).node().asLong();
    }
    CLDR cldr = ctx.cldr();
    CalendarDate start = cldr.Calendars.toGregorianDate(s, "UTC");
    CalendarDate end = cldr.Calendars.toGregorianDate(e, "UTC");
    RelativeTimeFormatOptions opts = OptionParsers.relativetime(args);
    String res = cldr.Calendars.formatRelativeTime(start, end, opts);
    v1.set(res);
}
Also used : CalendarDate(com.squarespace.cldrengine.api.CalendarDate) Variable(com.squarespace.template.Variable) CLDR(com.squarespace.cldrengine.CLDR) RelativeTimeFormatOptions(com.squarespace.cldrengine.api.RelativeTimeFormatOptions)

Example 2 with RelativeTimeFormatOptions

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

the class OptionParsers method relativetime.

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

Aggregations

RelativeTimeFormatOptions (com.squarespace.cldrengine.api.RelativeTimeFormatOptions)2 CLDR (com.squarespace.cldrengine.CLDR)1 CalendarDate (com.squarespace.cldrengine.api.CalendarDate)1 Variable (com.squarespace.template.Variable)1