Improve web signing flow and locale handling
This commit is contained in:
@@ -39,6 +39,34 @@ function getSignatureWidth(style, signerName = '') {
|
||||
return Math.max(170, Math.min(270, Math.round(calculatedWidth)));
|
||||
}
|
||||
|
||||
function buildLocalizedSignatureTimestamp({ locale, timeZone } = {}) {
|
||||
const now = new Date();
|
||||
const normalizedLocale = locale || 'es-EC';
|
||||
const options = timeZone ? { timeZone } : {};
|
||||
|
||||
try {
|
||||
return {
|
||||
dateStr: now.toLocaleDateString(normalizedLocale, {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
...options,
|
||||
}),
|
||||
timeStr: now.toLocaleTimeString(normalizedLocale, {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: true,
|
||||
...options,
|
||||
}),
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
dateStr: now.toLocaleDateString('es-EC', { day: '2-digit', month: '2-digit', year: 'numeric' }),
|
||||
timeStr: now.toLocaleTimeString('es-EC', { hour: '2-digit', minute: '2-digit', hour12: true }),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// ── Style: CLASSIC (blue bar + DS badge) ──────────────────────────────────────
|
||||
async function drawStyleClassic(pdfDoc, page, sx, sy, sw, sh, { signerName, reason, dateStr, timeStr, location }) {
|
||||
const f1 = await pdfDoc.embedFont(StandardFonts.HelveticaBold);
|
||||
@@ -222,6 +250,8 @@ const signPdf = async ({
|
||||
qrBackground = 'transparent',
|
||||
qrBorder = 'none',
|
||||
verificationUrl = null,
|
||||
clientLocale = null,
|
||||
clientTimeZone = null,
|
||||
outputDir = null,
|
||||
outputBaseName = null,
|
||||
}) => {
|
||||
@@ -258,9 +288,10 @@ const signPdf = async ({
|
||||
};
|
||||
const { x: sx, y: sy, width: sw, height: sh } = sigRect;
|
||||
|
||||
const now = new Date();
|
||||
const dateStr = now.toLocaleDateString('es-EC', { day: '2-digit', month: '2-digit', year: 'numeric' });
|
||||
const timeStr = now.toLocaleTimeString('es-EC', { hour: '2-digit', minute: '2-digit', hour12: true });
|
||||
const { dateStr, timeStr } = buildLocalizedSignatureTimestamp({
|
||||
locale: clientLocale,
|
||||
timeZone: clientTimeZone,
|
||||
});
|
||||
|
||||
const info = { signerName, reason, dateStr, timeStr, location, signatureImageBase64, verificationUrl, qrPosition, qrBackground, qrBorder };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user