Skip to content

Commit

Permalink
feat: add support orender on sheet date
Browse files Browse the repository at this point in the history
  • Loading branch information
JonDotsoy committed Oct 28, 2023
1 parent d94615d commit a83a598
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -70,6 +80,7 @@ export const handler = async function* (
showHelp,
template,
transformOptions,
outputAsSheet,
optionsLabels,
} = makeFlags(args);

Expand Down Expand Up @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions makeFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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; },
Expand Down Expand Up @@ -99,6 +101,7 @@ export function makeFlags(args: string[]) {
outputAsEpochMS,
outputAsJSON,
outputAsUTC,
outputAsSheet,
stdinReadable,
showHelp,
template,
Expand Down

0 comments on commit a83a598

Please sign in to comment.