All Projects → yavorsky → moment-cache

yavorsky / moment-cache

Licence: other
⏱ Simple utility to cache moment.js results and speed up moment calls.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to moment-cache

Angular Moment Picker
Angular Moment Picker is an AngularJS directive for date and time picker using Moment.js.
Stars: ✭ 536 (+1748.28%)
Mutual labels:  time, datetime, date, moment
format-date
📆 A small library (around 400 B when gziped & minified) to format JavaScript `Date` object using same tokens as moment.
Stars: ✭ 25 (-13.79%)
Mutual labels:  datetime, date, moment, moment-js
Dayjs
⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
Stars: ✭ 37,373 (+128772.41%)
Mutual labels:  time, datetime, date, moment
dayjs
Extended fork of Day.js - 2KB immutable date library alternative to Moment.js
Stars: ✭ 36 (+24.14%)
Mutual labels:  time, datetime, date, moment
chronos
One library to rule the time
Stars: ✭ 17 (-41.38%)
Mutual labels:  time, datetime, date, moment
rutimeparser
Recognize date and time in russian text and return datetime.datetime.
Stars: ✭ 17 (-41.38%)
Mutual labels:  time, datetime, date
qrono
🕥 Just right date time library
Stars: ✭ 111 (+282.76%)
Mutual labels:  time, datetime, date
shamsi date
A Flutter and Dart package for using Jalali (Shamsi, Solar, Persian or Jalaali) calendar. You can convert, format and manipulate Jalali and Gregorian (Miladi) date and times.
Stars: ✭ 59 (+103.45%)
Mutual labels:  time, datetime, date
dt
Go's missing DateTime package
Stars: ✭ 34 (+17.24%)
Mutual labels:  time, datetime, date
Gostradamus
Gostradamus: Better DateTimes for Go 🕰️
Stars: ✭ 148 (+410.34%)
Mutual labels:  time, datetime, date
Dpicker
A framework-agnostic minimal date picker
Stars: ✭ 187 (+544.83%)
Mutual labels:  time, datetime, date
relative.time.parser
Moment.js Plugin for parsing Relative Time Strings
Stars: ✭ 13 (-55.17%)
Mutual labels:  time, date, moment
Date
A date and time library based on the C++11/14/17 <chrono> header
Stars: ✭ 2,389 (+8137.93%)
Mutual labels:  time, datetime, date
hs-hourglass
efficient and simpler time API for haskell
Stars: ✭ 43 (+48.28%)
Mutual labels:  time, datetime, date
Time
Building a better date/time library for Swift
Stars: ✭ 1,983 (+6737.93%)
Mutual labels:  time, datetime, date
Jiffy
Jiffy is a Flutter (Android, IOS and Web) date time package inspired by momentjs for parsing, manipulating, querying and formatting dates
Stars: ✭ 238 (+720.69%)
Mutual labels:  time, datetime, date
lit-date
Light-weight, faster datetime formatter for modern browsers.
Stars: ✭ 33 (+13.79%)
Mutual labels:  time, datetime, date
iso8601
A fast ISO8601 date parser for Go
Stars: ✭ 122 (+320.69%)
Mutual labels:  time, datetime, date
imrc-datetime-picker
(Improved) React component datetime picker by momentjs 📆
Stars: ✭ 21 (-27.59%)
Mutual labels:  datetime, date, moment
Delorean
Delorean: Time Travel Made Easy
Stars: ✭ 1,793 (+6082.76%)
Mutual labels:  time, datetime, date

moment-cache

Moment-cache is a tiny tool to speed up your moment.js calls.

During the app lifecycle we can call moment oftentimes. Every call is time. Time is performance. This tool will increase performance of your app by caching moment.js instances.

Why?

  import moment from 'moment';
  import cache  from 'moment-cache';

  const dateString = '2016-08-24';
  const momentCalls = 99999;

  const check = (instance) => {
    let i = 0;
    const start = new Date;
    while (i <= momentCalls) {
      instance(dateString);
      i++;
    }
    return new Date - start;
  }

  console.log(check(moment));    // ~1588 ms
  console.log(check(cache));     // ~35 ms

Syntax:

Arguments:

  • date: See moment/parse.

  • format: See moment/format.

  • clone (by default - true): set false if you are not going to change instance in future. Will increase performance, but any object changes will affect cached result. See moment/clone.

  import cache from 'moment-cache'; // or moment().cache
  const myDate = '06-28-2016';
  const format = 'MM-DD-YYYY';
  const date = cache(myDate, format); // moment.js cached instance
  const anotherDate = cache(myDate, format); // rapidly retrieving previously processed result from the cache

Methods:

updateStorage: change cache destination.

Arguments:
  • storage: object where cache data is stored. By default - covert object behind the scenes.
  import cachable from 'moment-cache';
  const myStorage = {};
  cachable.updateStorage(myStorage);
  const date = cachable('2016-08-23');
  console.log(myStorage); // {1471899600000: Moment}
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].