0.1.1 • Published 2 years ago

@sonicgarden/time-elements v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

<time> element extensions

Installation

$ npm install @sonicgarden/time-elements

Usage

local-time

import '@sonicgarden/time-elements/dist/local-time-element'
<local-time datetime="2022-08-01 10:00:00" format="YYYY年MM月DD日(ddd) HH時mm分">
</local-time>

Attributes

  • datetime: Datetime string.
  • format: Format string. (default: YYYY-MM-DD HH:mm)
  • locale: Locale string. (default: undefined)

List of all available formats (YYYY-MM-DD HH:mm by default):

FormatOutputDescription
YY18Two-digit year
YYYY2018Four-digit year
M1-12The month, beginning at 1
MM01-12The month, 2-digits
D1-31The day of the month
DD01-31The day of the month, 2-digits
H0-23The hour
HH00-23The hour, 2-digits
h1-12The hour, 12-hour clock
hh01-12The hour, 12-hour clock, 2-digits
m0-59The minute
mm00-59The minute, 2-digits
s0-59The second
ss00-59The second, 2-digits
SSS000-999The millisecond, 3-digits
d0-6The day of the week, with Sunday as 0
ddS-SThe min name of the day of the week
dddSun-SatThe short name of the day of the week
ddddSunday-SaturdayThe name of the day of the week

time-ago

import '@sonicgarden/time-elements/dist/time-ago-element'
<time-ago datetime="2022-08-01 10:00:00" format="YYYY年MM月DD日(ddd) HH時mm分">
</time-ago>

Attributes

  • datetime: Datetime string.
  • format: Format string. (default: YYYY-MM-DD HH:mm)
  • locale: Locale string. (default: undefined)
  • interval: Interval seconds. (default: 30)
  • threshold: Threshold seconds. (default: 86400)

Browser support

Browsers without native custom element support require a polyfill.

  • Chrome
  • Firefox
  • Safari
  • Microsoft Edge

Development

pnpm install
pnpm test

License

Distributed under the MIT license. See LICENSE for details.