Add tz attribute to handlebar date function

Signed-off-by: chroju <chroju@users.noreply.github.com>
This commit is contained in:
chroju
2022-12-29 09:01:17 +09:00
parent c98ac5e987
commit 90a1d5cf21
10 changed files with 136 additions and 31 deletions

View File

@ -1,7 +1,7 @@
import * as handlebars from 'handlebars';
import * as fs from 'fs';
import * as path from 'path';
import moment from 'moment';
import moment from 'moment-timezone';
import * as pep440 from '@renovate/pep440';
import * as semver from 'semver';
import {Inputs, tmpDir} from './context';
@ -129,8 +129,19 @@ export class Meta {
const currentDate = this.date;
const vraw = this.setValue(
handlebars.compile(tag.attrs['pattern'])({
date: function (format) {
return moment(currentDate).utc().format(format);
date: function (format, options) {
const m = moment(currentDate);
let tz = 'UTC';
Object.keys(options.hash).forEach(key => {
switch (key) {
case 'tz':
tz = options.hash[key];
break;
default:
throw new Error(`Unknown ${key} attribute`);
}
});
return m.tz(tz).format(format);
}
}),
tag
@ -411,8 +422,19 @@ export class Meta {
}
return 'false';
},
date: function (format) {
return moment(currentDate).utc().format(format);
date: function (format, options) {
const m = moment(currentDate);
let tz = 'UTC';
Object.keys(options.hash).forEach(key => {
switch (key) {
case 'tz':
tz = options.hash[key];
break;
default:
throw new Error(`Unknown ${key} attribute`);
}
});
return m.tz(tz).format(format);
}
});
}

View File

@ -95,7 +95,7 @@ export function Parse(s: string): Tag {
for (const field of fields) {
const parts = field
.toString()
.split('=')
.split(/(?<=^[^=]+?)=/)
.map(item => item.trim());
if (parts.length == 1) {
tag.attrs['value'] = parts[0];