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