0.3.3 • Published 20 days ago

@kanziw/time v0.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
20 days ago

@kanziw/time

npm version license npm downloads

cancellableDelay

import { cancellableDelay } from '@kanziw/time'

const delay100 = cancellableDelay(100)
const delay1000 = cancellableDelay(1000)

// It takes about 100ms
await Promise.all([
  delay100.promise.finally(delay1000.cancel),
  delay1000.promise,
])

delay

import { delay } from '@kanziw/time'

// It takes about 100ms
await delay(100)

stopwatch

Measure elapsed ms using perf_hooks.performance

import { startStopwatch } from '@kanziw/time'
import { setTimeout as delay } from 'timers/promises'

const stopwatch = startStopwatch()
await delay(100)

const elapsedMs = stopwatch.end()
console.log(elapsedMs) // 100.74062514305115

timezone

time formatter

Format date to string with date, time and datetime format

import { formatWithTimezoneOffset, kstFormat, utcFormat } from '@kanziw/time'

const d = new Date('2022-05-16T00:00:00.000Z')
const dMs = d.getTime()

const timeFormatter = formatWithTimezoneOffset('+17:30')(d) // or formatWithTimezoneOffset('+17:30')(d)
console.log(`${timeFormatter.date()} / ${timeFormatter.time()} / ${timeFormatter.datetime()}`)
// 2022-05-16 / 17:30:00 / 2022-05-16 17:30:00

// utcFormat equals formatWithTimezoneOffset('+00:00')
const utc = utcFormat(d) // or utcFormat(dMs)
console.log(`${utc.date()} / ${utc.time()} / ${utc.datetime()}`)
// 2022-05-16 / 00:00:00 / 2022-05-16 00:00:00

// kstFormat equals formatWithTimezoneOffset('+09:00')
const kst = kstFormat(d) // or kstFormat(dMs)
console.log(`${kst.date()} / ${kst.time()} / ${kst.datetime()}`)
// 2022-05-16 / 09:00:00 / 2022-05-16 09:00:00
0.3.1-rc.3

20 days ago

0.3.1-rc.2

20 days ago

0.3.1-rc.1

20 days ago

0.3.1-rc.0

20 days ago

0.3.3-rc.2

20 days ago

0.3.3-rc.1

20 days ago

0.3.3-rc.0

20 days ago

0.3.0

20 days ago

0.3.2

20 days ago

0.3.1

20 days ago

0.3.3

20 days ago

0.2.2-rc.0

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.1.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.6

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago