UNPKG

@phensley/cldr-core

Version:
67 lines 2.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var types_1 = require("../../types"); // TODO: expose a method to calculate field difference with different options, e.g. // include weekdays var DateFieldInternalsImpl = /** @class */ (function () { function DateFieldInternalsImpl(internals) { this.internals = internals; this.relativeTimes = internals.schema.DateFields.relativeTimes; } DateFieldInternalsImpl.prototype.formatRelativeTime = function (bundle, start, end, options, params) { // TODO: need to compute integral difference for multiple fields. for example, year // may differ between 2017-12-01 and 2018-02-02 but they are only 3 months apart, so // we might format "3 months" or "9 weeks" or "9 Fridays" or "63 days". return ''; }; DateFieldInternalsImpl.prototype.formatRelativeTimeField = function (bundle, value, field, options, params) { var format; switch (options.width) { case 'narrow': format = this.relativeTimes.narrow; break; case 'short': format = this.relativeTimes.short; break; default: format = this.relativeTimes.wide; break; } var n = types_1.coerceDecimal(value); var negative = n.isNegative(); if (negative) { n = n.negate(); } if (n.compare(types_1.DecimalConstants.ZERO) === 0) { return format.current.get(bundle, field); } switch (field) { case 'hour': case 'minute': case 'second': break; default: if (n.compare(types_1.DecimalConstants.TWO) === 0) { var p = negative ? format.previous2.get(bundle, field) : format.next2.get(bundle, field); if (p !== '') { return p; } // Fall through } else if (n.compare(types_1.DecimalConstants.ONE) === 0) { return negative ? format.previous.get(bundle, field) : format.next.get(bundle, field); } break; } // Format a pluralized future / past. var operands = n.operands(); var plural = this.internals.plurals.cardinal(bundle.language(), operands); var arrow = negative ? format.past : format.future; var raw = arrow.get(bundle, plural, field); var num = params.system.formatString(n, false, 1); return this.internals.wrapper.format(raw, [num]); }; return DateFieldInternalsImpl; }()); exports.DateFieldInternalsImpl = DateFieldInternalsImpl; //# sourceMappingURL=internal.js.map