use of com.squarespace.cldrengine.api.CalendarDate 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);
}
use of com.squarespace.cldrengine.api.CalendarDate 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);
}
use of com.squarespace.cldrengine.api.CalendarDate 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.CalendarDate 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.CalendarDate 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