An open API service indexing awesome lists of open source software.

https://github.com/hedyhli/deno-datefmt

Unambiguous Golang-style date formatting library for Deno.
https://github.com/hedyhli/deno-datefmt

deno library typescript

Last synced: 6 months ago
JSON representation

Unambiguous Golang-style date formatting library for Deno.

Awesome Lists containing this project

README

          

# datefmt

[![Checks](https://github.com/hedyhli/deno-datefmt/actions/workflows/deno.yml/badge.svg)](https://github.com/hedyhli/deno-datefmt/actions/workflows/deno.yml)
![deno-coverage](https://img.shields.io/badge/Coverage-100%25-2ebb4e)

```js
import datefmt from "https://deno.land/x/datefmt/mod.ts"

datefmt(new Date(1999, 5, 4), "[JAN]. [2nd], [2006]")
=> "MAR. 4th, 1999"
```

- Similar to Golang's date(time) formats, but delimiters around format
specifiers are required. This makes formatting less ambiguous.
- 'nth' day formats are supported
- All forms of capitalization and zero-padding are both supported.

The default delimiters are `[]`.

Delimiters can optionally be the same character.

```js
// Use single quote for both start and end delim
datefmt(date, "'2006' 'January'", true, "'")

// Use < for start, and | for the end delim.
datefmt(date, "<2006| `"A[]B"`
- `A[[]B` => `"A[B"`
- `A[]]B` => `"A]B"`

If delimiters are the same character, where `delim = "."`:
- `A.B` => `A.B`
- `A..B` => `A..B`
- `A...B` => `A.B`

## Supported format specifiers

The standard date used is `Monday, January 2nd 03:04:05 PM 2006`

Tip for memorising: `01/02 03:04:05 2006 (PM) (Monday)`

Use any of the following format specifiers from within delimiters (by default,
`[]`), and they will be replaced with the corresponding value from the Date
object.

Date
- 2006, 06, 6
- 01, 1
- Jan, jan, JAN, January, january, JANUARY
- 02, 2
- 2nd, 2ND

Day
- Mon, mon, MON, Monday, monday, MONDAY

Time
- PM, Pm, pm
- 3, 03
- 15 (24-hour time), 015
- 4, 04
- 5, 05

Note, `"015"` is a special format for both 24-houur time and zero-padded. I.e.,
if the time is 9 AM, "15" and "3" both gives "9", whereas "015" and "03" both
gives "09".