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);
}
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;
}
Aggregations