mirror of
https://github.com/docker/metadata-action.git
synced 2025-07-05 09:48:24 +02:00
Add tz attribute to handlebar date function
Signed-off-by: chroju <chroju@users.noreply.github.com>
This commit is contained in:
32
src/meta.ts
32
src/meta.ts
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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];
|
||||
|
Reference in New Issue
Block a user