diff --git a/handler.ts b/handler.ts index 6beeb3a..b5bfa41 100644 --- a/handler.ts +++ b/handler.ts @@ -7,6 +7,16 @@ import { import { renderDateTemplate } from "./lib/renderDateTemplate.ts"; import { makeFlags } from "./makeFlags.ts"; +const renderSheet = (date: Date) => { + const year = date.getFullYear(); + const month = date.getMonth() + 1; + const dayOfMonth = date.getDate(); + const hours = date.getHours(); + const minutes = date.getMinutes(); + const seconds = date.getSeconds(); + return `=DATE(${year};${month};${dayOfMonth})+TIME(${hours};${minutes};${seconds})`; +}; + const makeHelpDialog = function* ( transformOptions: Record< string, @@ -70,6 +80,7 @@ export const handler = async function* ( showHelp, template, transformOptions, + outputAsSheet, optionsLabels, } = makeFlags(args); @@ -103,6 +114,7 @@ export const handler = async function* ( if (outputAsEpoch) return Math.floor(date.getTime() / 1000).toString(); if (outputAsJSON) return date.toJSON(); if (outputAsUTC) return date.toUTCString(); + if (outputAsSheet) return renderSheet(date); return date.toLocaleString(local, { dateStyle: toDateStyle(dateStyle), timeStyle: toTimeStyle(timeStyle), diff --git a/makeFlags.ts b/makeFlags.ts index d8443ed..7da1418 100644 --- a/makeFlags.ts +++ b/makeFlags.ts @@ -22,6 +22,7 @@ export function makeFlags(args: string[]) { let outputAsEpochMS = false; let outputAsJSON = false; let outputAsUTC = false; + let outputAsSheet = false; let stdinReadable = false; let showHelp = false; let template: string | undefined; @@ -37,6 +38,7 @@ export function makeFlags(args: string[]) { '--local': (nextArgument) => { local = nextArgument(); }, '--template': (nextArgument) => { template = nextArgument(); }, '--json': () => { outputAsJSON = true; }, + '--sheet': () => { outputAsSheet = true; }, '--utc': () => { outputAsUTC = true; }, '--epoch': () => { outputAsEpoch = true; }, '--epoch-ms': () => { outputAsEpochMS = true; }, @@ -99,6 +101,7 @@ export function makeFlags(args: string[]) { outputAsEpochMS, outputAsJSON, outputAsUTC, + outputAsSheet, stdinReadable, showHelp, template,