All Projects → mcibique → vue-date-fns

mcibique / vue-date-fns

Licence: MIT license
Date filter for Vue based on the date-fns.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to vue-date-fns

Swiftdate
🐔 Toolkit to parse, validate, manipulate, compare and display dates, time & timezones in Swift.
Stars: ✭ 6,661 (+31619.05%)
Mutual labels:  date, date-formatting
Date Fns
⏳ Modern JavaScript date utility library ⌛️
Stars: ✭ 27,650 (+131566.67%)
Mutual labels:  date, date-fns
react-daterange-picker
A react date range picker to using @material-ui. Live Demo: https://flippingbitss.github.io/react-daterange-picker/
Stars: ✭ 85 (+304.76%)
Mutual labels:  date, date-fns
format-date
📆 A small library (around 400 B when gziped & minified) to format JavaScript `Date` object using same tokens as moment.
Stars: ✭ 25 (+19.05%)
Mutual labels:  date, date-formatting
Time
Building a better date/time library for Swift
Stars: ✭ 1,983 (+9342.86%)
Mutual labels:  date, date-formatting
Dayjs
⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
Stars: ✭ 37,373 (+177866.67%)
Mutual labels:  date, date-formatting
dayjs
Extended fork of Day.js - 2KB immutable date library alternative to Moment.js
Stars: ✭ 36 (+71.43%)
Mutual labels:  date, date-formatting
Pgo
Go library for PHP community with convenient functions
Stars: ✭ 51 (+142.86%)
Mutual labels:  date, filter
go-prettytime
Format GoLang dates in a “pretty” way. ex : just now, a minute ago, 2 hours ago , 3 minutes ago
Stars: ✭ 23 (+9.52%)
Mutual labels:  date, date-formatting
Caterpillar
🐛 Caterpillar: Type-safe date formats in Swift, no more "yyyy-MM-dd'T'HH:mm:ssZ"
Stars: ✭ 49 (+133.33%)
Mutual labels:  date, date-formatting
grayscale
macOS status bar app for easily toggling the grayscale display filter
Stars: ✭ 20 (-4.76%)
Mutual labels:  filter
jackson-dynamic-filter
An easy way to determine filters dynamically using Jackson
Stars: ✭ 35 (+66.67%)
Mutual labels:  filter
laravel-filter
Configurable and modular approach to query Filters for Laravel
Stars: ✭ 85 (+304.76%)
Mutual labels:  filter
laravel-searchzy
Package que te permite buscar y filtrar registros de Eloquent Models en Laravel de una manera simple y sencilla.
Stars: ✭ 15 (-28.57%)
Mutual labels:  filter
LunarCalendar
A lightweight macOS App for displaying calendar and time
Stars: ✭ 82 (+290.48%)
Mutual labels:  date
rescript-date
📆 Date manipulation in ReScript.
Stars: ✭ 101 (+380.95%)
Mutual labels:  date
js-calendar
The lightest Javascript calendar out there, without any dependency.
Stars: ✭ 37 (+76.19%)
Mutual labels:  date
dubbox
dubbox原始版本的升级版,主要根据GitHub各路大神代码的整合
Stars: ✭ 13 (-38.1%)
Mutual labels:  filter
restatapi
An R package to search and retrieve data from Eurostat database using SDMX
Stars: ✭ 14 (-33.33%)
Mutual labels:  filter
prototyped.js
Some common Typescript prototypes
Stars: ✭ 22 (+4.76%)
Mutual labels:  date

Date filter for Vue 2.X based on date-fns

npm version minzipped size

The format function from date-fns available as a filter for Vue apps. Why date-fns and not moment.js? There are already few articles, covering, that.

Disclaimer

This package is just a Vue 2.X wrapper around date-fns. All important (and excellent) stuff is happening inside the date-fns library. If you found a bug please report it in their issue tracker or help them and contribute the PR. If you like their package, support them, because they're doing an amazing job.

Installation

npm install vue-date-fns --save

or

yarn add vue-date-fns

vue-date-fns depends on date-fns version 2. If you are using the version 1 of date-fns, then install vue-date-fns@1, which is compatible.

Breaking changes in version 2

vue-date-fns@2 inherits all breaking changes from date-fns@2, because it's just a wrapper around their format function. There were major breaking changes in the format API, e.g. DD MMMM YYYY should be from now on dd MMMM yyyy.

Before upgrading to date-fns@2 and vue-date-fns@2, please check date-fns docs for format function, their blog explaining changes in the format and their changelog for common breaking changes in the date-fns library. It is very likely that your existing code will break.

Usage

Filter in individual component

You can use filter directly in your component.

// my-component.js
import { dateFilter } from "vue-date-fns";

export default {
    filters: {
        date: dateFilter
    }
}
<!-- my-component.vue -->
<template>
    <div>Now: {{ new Date() | date }}</div>
</template>

Global filter

You can register the filter globally in your app.

// main.js
import { dateFilter } from "vue-date-fns";

Vue.filter("date", dateFilter);
<!-- my-component.vue -->
<template>
    <div>Now: {{ new Date() | date }}</div>
</template>

Global filter and mixin

You can also use the filter as a mixin if you install the entire plugin.

// main.js
import VueDateFns from "vue-date-fns";

Vue.use(VueDateFns);
// my-component.js
export default {
    computed: {
        now() {
            return this.$date(new Date());
        }
    }
}
<!-- my-component.vue -->
<template>
    <div>
        <div>Now: {{ now }}</div>
        <div>Now: {{ new Date() | date }}</div>
        <div>Now: {{ $date(new Date()) }}</div>
    </div>
</template>

Options

The filter and mixin support the same arguments as the original format function (see docs):

format(date, format, [options])

So you can do this:

<!-- my-component.vue -->
<template>
    <div>
        <div>Now: {{ new Date() | date('dd MMMM yyyy') }}</div>
        <div>Now: {{ $date(new Date(), 'dd MMMM yyyy') }}</div>
    </div>
</template>

or provide custom locale:

// my-component.js
import locale from "date-fns/locale/sk";

export default {
    computed: {
        now() {
            return this.$date(new Date(), "dd MMMM yyyy", { locale });
        }
    }
}

Overriding default options

The default date format and default locale options are the same as for the original format function (see the docs). There is a way how to set your own:

Filter in individual component

Instead of importing the dateFilter, import createDateFilter factory function and use it for creating the dateFilter with your own defaults:

// my-component.js
import { createDateFilter } from "vue-date-fns";
import locale from "date-fns/locale/sk";

export default {
    filters: {
        date: createDateFilter("dd MMMM yyyy", { locale })
    }
}

Global filter

Instead of importing the dateFilter, import createDateFilter factory function and use it for creating the dateFilter with your own defaults:

// main.js
import { createDateFilter } from "vue-date-fns";
import locale from "date-fns/locale/sk";

Vue.filter("date", createDateFilter("dd MMMM yyyy", { locale }));

Global filter and mixin

Pass the new defaults as other parameters to the .use() call. The defaults are applied for global filter and mixin.

// main.js
import VueDateFns from "vue-date-fns";

Vue.use(VueDateFns, "dd MMMM yyyy", { locale });

Customize the global filter name

If you want to change the global name of the filter and mixin, pass the fourth argument into the .use() call. If the value is falsy, it defaults to "date".

// main.js
import VueDateFns from "vue-date-fns";

Vue.use(VueDateFns, /* custom format */, /* custom options */, "myDateFilter");
<!-- my-component.vue -->
<template>
    <div>
        <div>Now: {{ new Date() | myDateFilter }}</div>
        <div>Now: {{ new Date() | myDateFilter('dd MMMM yyyy') }}</div>
        <div>Now: {{ $myDateFilter(new Date(), 'dd MMMM yyyy') }}</div>
    </div>
</template>

Default date format

If you don't set up any default format for your custom filters, vue-date-fns will automatically set it to yyyy-MM-dd'T'HH:mm:ss.SSSxxx, following the migration guide of date-fns.

If you would like to change the default format, follow the Overriding default options section and create a custom filter with custom defaults.

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].