Skip to content

Commit

Permalink
feat: upgrade template and permisions
Browse files Browse the repository at this point in the history
  • Loading branch information
JonDotsoy committed Jul 14, 2023
1 parent 42e3ade commit c9e767a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Usage: ndate [-] [--zero] [--date-style <full|long|medium|short>] [--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:
Expand All @@ -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`
Expand Down Expand Up @@ -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**
Expand Down
31 changes: 23 additions & 8 deletions ndate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
])

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c9e767a

Please sign in to comment.