All Projects → aweary → Tinytime

aweary / Tinytime

Licence: mit
⏰ A straightforward date and time formatter in <1kb

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Tinytime

Tinydate
A tiny (349B) reusable date formatter. Extremely fast!
Stars: ✭ 990 (-24.6%)
Mutual labels:  time, date
Laydate
layDate(日期与时间组件) 是 layui 独立维护的三大组件之一
Stars: ✭ 1,066 (-18.81%)
Mutual labels:  time, date
Period
Complex period comparisons
Stars: ✭ 1,001 (-23.76%)
Mutual labels:  time, date
Vue Datetime
Mobile friendly datetime picker for Vue. Supports date and datetime modes, i18n and more.
Stars: ✭ 928 (-29.32%)
Mutual labels:  time, date
Graphql Java Datetime
GraphQL ISO Date is a set of RFC 3339 compliant date/time scalar types to be used with graphql-java.
Stars: ✭ 89 (-93.22%)
Mutual labels:  time, date
Dayjs
⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
Stars: ✭ 37,373 (+2746.38%)
Mutual labels:  time, date
Zulu
A drop-in replacement for native Python datetimes that embraces UTC.
Stars: ✭ 52 (-96.04%)
Mutual labels:  time, date
Vue Ctk Date Time Picker
VueJS component to select dates & time, including a range mode
Stars: ✭ 707 (-46.15%)
Mutual labels:  time, date
Timezone Support
Lightweight time zone support for your applications or other date libraries.
Stars: ✭ 90 (-93.15%)
Mutual labels:  time, date
Xfce4 Genmon Scripts
🐭 XFCE panel generic monitor scripts
Stars: ✭ 69 (-94.74%)
Mutual labels:  time, date
Singledateandtimepicker
You can now select a date and a time with only one widget !
Stars: ✭ 921 (-29.86%)
Mutual labels:  time, date
Carbon
A simple PHP API extension for DateTime
Stars: ✭ 75 (-94.29%)
Mutual labels:  time, date
Moment.php
Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
Stars: ✭ 900 (-31.45%)
Mutual labels:  time, date
React Picky Date Time
A react component for date time picker. Online demo examples
Stars: ✭ 31 (-97.64%)
Mutual labels:  time, date
Translatedjs
Internationalization and localization for JavaScript and Node.js
Stars: ✭ 17 (-98.71%)
Mutual labels:  time, date
Pickadate.js
The mobile-friendly, responsive, and lightweight jQuery date & time input picker.
Stars: ✭ 7,753 (+490.48%)
Mutual labels:  time, date
Period
PHP's time range API
Stars: ✭ 616 (-53.08%)
Mutual labels:  time, date
Date Fns
⏳ Modern JavaScript date utility library ⌛️
Stars: ✭ 27,650 (+2005.86%)
Mutual labels:  time, date
When
A natural language date/time parser with pluggable rules
Stars: ✭ 1,113 (-15.23%)
Mutual labels:  time, date
Iso8601
Ruby parser to work with ISO8601 dateTimes and durations — http://en.wikipedia.org/wiki/ISO_8601
Stars: ✭ 70 (-94.67%)
Mutual labels:  time, date

Tinytime ⏰

A straightforward date and time formatter in <800b.

npm travis

API

tinytime exports a single function that returns a template object. This object has a single method, render, which takes a Date and returns a string with the rendered data.

import tinytime from 'tinytime';
const template = tinytime('The time is {h}:{mm}:{ss}{a}.');
template.render(new Date());
// The time is 11:10:20PM.

Substitutions

  • MMMM - Full Month (September)
  • MM - Partial Month (Sep)
  • Mo - Numeric Month (9) 1
  • YYYY - Full Year (1992)
  • YY - Partial Year (92)
  • dddd - Day of the Week (Monday)
  • DD - Day of the Month (24)
  • Do - Day (24th)
  • h - Hours - 12h format
  • H - Hours - 24h format
  • mm - Minutes (zero padded)
  • ss - Seconds (zero padded)
  • a - AM/PM

1 - you get padded months (09 instead of 9) by passing in the padMonth option.

const template = tinytime('{Mo}', { padMonth: true })

Efficiency

tinytime takes an approach similar to a compiler and generates an AST representing your template. This AST is generated when you call the main tinytime function. This lets you efficiently re-render your template without tinytime having to parse the template string again. That means its important that you aren't recreating the template object frequently.

Here's an example showing the right and wrong way to use tinytime with React.

Don't do this:

function Time({ date }) {
  return (
    <div>
      {tinytime('{h}:{mm}:{ss}{a}').render(date)}
    </div>
  )
}

Instead, only create the template object once, and just re-render it.

const template = tinytime('{h}:{mm}:{ss}{a}');
function Time({ date }) {
  return (
    <div>
      {template.render(date)}
    </div>
  )
}

Babel Plugins

Using one of the plugins below, you can resolve this efficiency concern at compile time.

babel-plugin-transform-tinytime - Hoists tinytime calls out of the JSX render scope.

babel-plugin-tinytime - Hoists tinytime calls out of the current scope, regardless if its inside JSX or a ordinary function scope.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].