diff --git a/README.md b/README.md index f01ac58..af12704 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Usage: ndate [-] [--zero] [--date-style ] [--time-style Install with [homebrew](https://brew.sh/): ```shell -brew install jondotsoy/ndate/ndate +brew install --allow-env=TZ,LANG jondotsoy/ndate/ndate ``` Or install with deno: @@ -37,6 +37,7 @@ ndate --epoch # 1689255846 ndate --epoch-ms # 1689255823663 ndate --epoch-ms -z # 1689255823663% ndate --template '{{utc_full_year}}-{{utc_month:padStart:2:0}}-{{utc_date:padStart:2:0}}' # 2023-06-13 +ndate --template '{{YYYY}}{{MM}}{{DD}}{{HH}}{{MM}}{{SS}}{{MS}}' # 202330142030590781 ``` ## Options to `--template` @@ -78,6 +79,13 @@ ndate --template '{{utc_full_year}}-{{utc_month:padStart:2:0}}-{{utc_date:padSta - `{{local_timeZoneName}}`: `timeZoneName` part of `Intl.DateTimeFormat` - `{{local_weekday}}`: `weekday` part of `Intl.DateTimeFormat` - `{{local_year}}`: `year` part of `Intl.DateTimeFormat` +- `{{YYYY}}`: Full year in local time. Ej. `2023`. +- `{{MM}}`: Month in local time. Ej. `07`, `12`. +- `{{DD}}`: Day of month in local time. Ej. `09`, `31`. +- `{{HH}}`: Hour in local time. Ej. `06`, `18`. +- `{{MM}}`: Minute in local time. Ej. `23`, `59`. +- `{{SS}}`: Second in local time. Ej. `13`, `30`. +- `{{MS}}`: Millisecond in local time. Ej. `0456`, `998`. **Sample** diff --git a/ndate.ts b/ndate.ts index 1879f36..4d7df27 100755 --- a/ndate.ts +++ b/ndate.ts @@ -20,23 +20,35 @@ function renderDateTemplate(template: string, date: Date, locales?: string, opti [`rfc7231`, utcString], [`local`, localeString], ["time", date.getTime()], + + ["YYYY", date.getFullYear().toString().padStart(4,`0`)], + ["MM", (date.getMonth() + 1).toString().padStart(2,`0`)], + ["DD", date.getDate().toString().padStart(2,`0`)], + + ["HH", date.getHours().toString().padStart(2,`0`)], + ["MM", date.getMinutes().toString().padStart(2,`0`)], + ["SS", date.getSeconds().toString().padStart(2,`0`)], + ["MS", date.getMilliseconds().toString().padStart(4,`0`)], + + ["full_year", date.getFullYear()], - ["utc_full_year", date.getUTCFullYear()], ["month", date.getMonth() + 1], - ["utc_month", date.getUTCMonth() + 1], ["date", date.getDate()], - ["utc_date", date.getUTCDate()], ["day", date.getDay()], - ["utc_day", date.getUTCDay()], ["hours", date.getHours()], - ["utc_hours", date.getUTCHours()], ["minutes", date.getMinutes()], - ["utc_minutes", date.getUTCMinutes()], ["seconds", date.getSeconds()], - ["utc_seconds", date.getUTCSeconds()], ["milliseconds", date.getMilliseconds()], - ["utc_milliseconds", date.getUTCMilliseconds()], ["timezone_offset", date.getTimezoneOffset()], + + ["utc_full_year", date.getUTCFullYear()], + ["utc_month", date.getUTCMonth() + 1], + ["utc_date", date.getUTCDate()], + ["utc_day", date.getUTCDay()], + ["utc_hours", date.getUTCHours()], + ["utc_minutes", date.getUTCMinutes()], + ["utc_seconds", date.getUTCSeconds()], + ["utc_milliseconds", date.getUTCMilliseconds()], ...parts, ]) @@ -201,6 +213,9 @@ const run = async () => { return; } + if (timeZone) Deno.env.set(`TZ`, timeZone) + if (local) Deno.env.set(`LANG`, local) + if (stdinReadable) { const buff = new Uint8Array(256); await Deno.stdin.read(buff);