All Projects β†’ taylorhakes β†’ Fecha

taylorhakes / Fecha

Licence: mit
Lightweight and simple JS date formatting and parsing

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Fecha

Gostradamus
Gostradamus: Better DateTimes for Go πŸ•°οΈ
Stars: ✭ 148 (-92.43%)
Mutual labels:  parsing, date
Maya
Datetimes for Humansβ„’
Stars: ✭ 3,298 (+68.7%)
Mutual labels:  parsing, date
Moment.php
Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
Stars: ✭ 900 (-53.96%)
Mutual labels:  parsing, date
Datedelta
Date arithmetic in Python
Stars: ✭ 135 (-93.09%)
Mutual labels:  date
React Calendar
Ultimate calendar for your React app.
Stars: ✭ 2,082 (+6.5%)
Mutual labels:  date
Anytime
Anything to POSIXct or Date Converter
Stars: ✭ 137 (-92.99%)
Mutual labels:  date
Pizza Sync
Pizza-Sync is a web app built on the frontend with angular, ngrx and on the backend with Nest. It let you and your friends/colleagues choose a pizza before placing a group order. Built using https://github.com/maxime1992/angular-ngrx-starter
Stars: ✭ 158 (-91.92%)
Mutual labels:  parsing
Untrusted
Safe, fast, zero-panic, zero-crashing, zero-allocation parsing of untrusted inputs in Rust.
Stars: ✭ 133 (-93.2%)
Mutual labels:  parsing
Rats
Movie Ratings Synchronization with Python
Stars: ✭ 156 (-92.02%)
Mutual labels:  parsing
Date Picker
πŸ“… Custom responsive date picker widget for Android, written in Kotlin.
Stars: ✭ 146 (-92.53%)
Mutual labels:  date
Parjs
JavaScript parser-combinator library
Stars: ✭ 145 (-92.58%)
Mutual labels:  parsing
Tail.datetime
A lightweight, translat- and configurable Open Source DateTime Picker, written in pure vanilla JavaScript!
Stars: ✭ 139 (-92.89%)
Mutual labels:  date
Wikitextparser
A simple WikiText parsing library for MediaWiki
Stars: ✭ 149 (-92.38%)
Mutual labels:  parsing
Cyberchef
The Cyber Swiss Army Knife - a web app for encryption, encoding, compression and data analysis
Stars: ✭ 13,674 (+599.44%)
Mutual labels:  parsing
Abot
Cross Platform C# web crawler framework built for speed and flexibility. Please star this project! +1.
Stars: ✭ 1,961 (+0.31%)
Mutual labels:  parsing
Down
Blazing fast Markdown / CommonMark rendering in Swift, built upon cmark.
Stars: ✭ 1,895 (-3.07%)
Mutual labels:  parsing
Ngx Date Fns
⏳ date-fns pipes for Angular 2.0 and above ⏳
Stars: ✭ 135 (-93.09%)
Mutual labels:  date
Delorean
Delorean: Time Travel Made Easy
Stars: ✭ 1,793 (-8.29%)
Mutual labels:  date
Rosie Pattern Language
Rosie Pattern Language (RPL) and the Rosie Pattern Engine have MOVED!
Stars: ✭ 146 (-92.53%)
Mutual labels:  parsing
Filtrex
A library for performing and validating complex filters from a client (e.g. smart filters)
Stars: ✭ 157 (-91.97%)
Mutual labels:  parsing

fecha Build Status

Lightweight date formatting and parsing (~2KB). Meant to replace parsing and formatting functionality of moment.js.

NPM

npm install fecha --save

Yarn

yarn add fecha

Fecha vs Moment

Fecha Moment
Size (Min. and Gzipped) 2.1KBs 13.1KBs
Date Parsing βœ“ βœ“
Date Formatting βœ“ βœ“
Date Manipulation βœ“
I18n Support βœ“ βœ“

Use it

Formatting

format accepts a Date object (or timestamp) and a string format and returns a formatted string. See below for available format tokens.

Note: format will throw an error when passed invalid parameters

import { format } from 'fecha';

type format = (date: Date, format?: string, i18n?: I18nSettings) => str;

// Custom formats
format(new Date(2015, 10, 20), 'dddd MMMM Do, YYYY'); // 'Friday November 20th, 2015'
format(new Date(1998, 5, 3, 15, 23, 10, 350), 'YYYY-MM-DD hh:mm:ss.SSS A'); // '1998-06-03 03:23:10.350 PM'

// Named masks
format(new Date(2015, 10, 20), 'isoDate'); // '2015-11-20'
format(new Date(2015, 10, 20), 'mediumDate'); // 'Nov 20, 2015'
format(new Date(2015, 10, 20, 3, 2, 1), 'isoDateTime'); // '2015-11-20T03:02:01-05:00'
format(new Date(2015, 2, 10, 5, 30, 20), 'shortTime'); // '05:30'

// Literals
format(new Date(2001, 2, 5, 6, 7, 2, 5), '[on] MM-DD-YYYY [at] HH:mm'); // 'on 03-05-2001 at 06:07'

Parsing

parse accepts a Date string and a string format and returns a Date object. See below for available format tokens.

NOTE: parse will throw an error when passed invalid string format or missing format. You MUST specify a format.

import { parse } from 'fecha';

type parse = (dateStr: string, format: string, i18n?: I18nSettingsOptional) => Date|null;

// Custom formats
parse('February 3rd, 2014', 'MMMM Do, YYYY'); // new Date(2014, 1, 3)
parse('10-12-10 14:11:12', 'YY-MM-DD HH:mm:ss'); // new Date(2010, 11, 10, 14, 11, 12)

// Named masks
parse('5/3/98', 'shortDate'); // new Date(1998, 4, 3)
parse('November 4, 2005', 'longDate'); // new Date(2005, 10, 4)
parse('2015-11-20T03:02:01-05:00', 'isoDateTime'); // new Date(2015, 10, 20, 3, 2, 1)

// Override i18n
parse('4 de octubre de 1983', 'M de MMMM de YYYY', {
  monthNames: [
    'enero',
    'febrero',
    'marzo',
    'abril',
    'mayo',
    'junio',
    'julio',
    'agosto',
    'septiembre',
    'octubre',
    'noviembre',
    'diciembre'
  ]
}); // new Date(1983, 9, 4)

i18n Support

import {setGlobalDateI18n} from 'fecha';

/*
Default I18n Settings
{
  dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat'],
  dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  amPm: ['am', 'pm'],
  // D is the day of the month, function returns something like...  3rd or 11th
  DoFn(dayOfMonth) {
    return dayOfMonth + [ 'th', 'st', 'nd', 'rd' ][ dayOfMonth % 10 > 3 ? 0 : (dayOfMonth - dayOfMonth % 10 !== 10) * dayOfMonth % 10 ];
  }
}
*/

setGlobalDateI18n({
  dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat'],
  dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  amPm: ['am', 'pm'],
  // D is the day of the month, function returns something like...  3rd or 11th
  DoFn: function (D) {
    return D + [ 'th', 'st', 'nd', 'rd' ][ D % 10 > 3 ? 0 : (D - D % 10 !== 10) * D % 10 ];
  }
});

Custom Named Masks

import { format, setGlobalDateMasks } from 'fecha';
/*
Default global masks
{
  default: 'ddd MMM DD YYYY HH:mm:ss',
  shortDate: 'M/D/YY',
  mediumDate: 'MMM D, YYYY',
  longDate: 'MMMM D, YYYY',
  fullDate: 'dddd, MMMM D, YYYY',
  shortTime: 'HH:mm',
  mediumTime: 'HH:mm:ss',
  longTime: 'HH:mm:ss.SSS'
}
*/

// Create a new mask
setGlobalDateMasks({
  myMask: 'HH:mm:ss YY/MM/DD';
});

// Use it
format(new Date(2014, 5, 6, 14, 10, 45), 'myMask'); // '14:10:45 14/06/06'

Formatting Tokens

Token Output
Month M 1 2 ... 11 12
MM 01 02 ... 11 12
MMM Jan Feb ... Nov Dec
MMMM January February ... November December
Day of Month D 1 2 ... 30 31
Do 1st 2nd ... 30th 31st
DD 01 02 ... 30 31
Day of Week d 0 1 ... 5 6
ddd Sun Mon ... Fri Sat
dddd Sunday Monday ... Friday Saturday
Year YY 70 71 ... 29 30
YYYY 1970 1971 ... 2029 2030
AM/PM A AM PM
a am pm
Hour H 0 1 ... 22 23
HH 00 01 ... 22 23
h 1 2 ... 11 12
hh 01 02 ... 11 12
Minute m 0 1 ... 58 59
mm 00 01 ... 58 59
Second s 0 1 ... 58 59
ss 00 01 ... 58 59
Fractional Second S 0 1 ... 8 9
SS 0 1 ... 98 99
SSS 0 1 ... 998 999
Timezone Z -07:00 -06:00 ... +06:00 +07:00
ZZ -0700 -0600 ... +0600 +0700
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].