"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NowHelper = void 0;
const handlebars_1 = __importDefault(require("handlebars"));
const moment_1 = __importDefault(require("moment"));
/**
* Defines and registers custom handlebar helper - now
*/
class NowHelper {
constructor() {
/**
* Registers now helper
* - If now helper is called without a format, set a default format as YYYY-MM-DD hh:mm:ss else use the format provided
* - Set default offset to be used if offset is not specified. Default offset is 0s i.e. no offset
* - If offset is defined the value will be stored in context.hash.offset, eg X days.
* - Split value by a space, first element will be the amount of offset i.e. X, second element will be unit of offset, i.e. days
* - Return a value with specified format and added offset
* @returns {void}
*/
this.register = () => {
handlebars_1.default.registerHelper("now", (context) => {
const format = typeof context.hash.format === "undefined" ? "YYYY-MM-DD hh:mm:ss" : context.hash.format;
let offsetUnit = "s";
let offsetAmount = 0;
if (typeof context.hash.offset !== "undefined") {
let offset = context.hash.offset.split(" ");
offsetAmount = offset[0];
offsetUnit = offset[1];
}
switch (format) {
case "epoch":
return moment_1.default().add(offsetAmount, offsetUnit).format("x");
case "unix":
return moment_1.default().add(offsetAmount, offsetUnit).format("X");
default:
return moment_1.default().add(offsetAmount, offsetUnit).format(format);
}
});
};
}
}
exports.NowHelper = NowHelper;
//# sourceMappingURL=NowHelper.js.map