Giter VIP home page Giter VIP logo

date-io's Introduction

date-io

Stand With Ukraine

Abstraction over common JavaScript date management libraries.

npm package codecov typescript travis lerna code style: prettier

The project exposes an abstraction interface over luxon, date-fns v3, dayjs and moment. It allows you to build any UI date or time components while utilizing the same date management library in use within your user's project.

It simplifies timezone management, allows your code to return the exact same type that your user expects and works with specific calendar systems (e.g. Jalali calendar)

Projects

Library Downloads
@date-io/date-fns npm download
@date-io/moment npm download
@date-io/luxon npm download
@date-io/dayjs npm download
@date-io/js-joda npm download
@date-io/date-fns-jalali npm download
@date-io/jalaali npm download
@date-io/hijri npm download

Usage example

import LuxonAdapter from "@date-io/luxon";
import DateFnsAdapter from "@date-io/date-fns";

const dateFns = new DateFnsAdapter();
const luxon = new LuxonAdapter({ locale: "fr" }); // pass french locale

const initialLuxonDate = luxon.date("2018-10-28T11:44:00.000Z");
const initialDateFnsDate = dateFns.date("2018-10-28T11:44:00.000Z");

const updatedLuxonDate = luxon.addDays(initialLuxonDate, 2);
const updatedDateFnsDate = dateFns.addDays(initialDateFnsDate, 2);

luxon.format(updatedLuxonDate, "fullDateTime24h"); // "2018, octobre 30 11:44"
dateFns.format(updatedLuxonDate, "fullDateTime24h"); // "2018, October 30th 11:44"

Interface

The implemented interface. If you cannot find the method you require, please let us know, and we will add it!

Localized output will of course vary based on the locale and date library used. Inline examples here are based on using moment with the en-US locale.

export interface DateIOFormats<TLibFormatToken = string> {
  /** Localized full date @example "Jan 1, 2019" */
  fullDate: TLibFormatToken;
  /** Partially localized full date with weekday, useful for text-to-speech accessibility @example "Tuesday, January 1, 2019" */
  fullDateWithWeekday: TLibFormatToken;
  /** Date format string with month and day of month @example "1 January" */
  normalDate: TLibFormatToken;
  /** Date format string with weekday, month and day of month @example "Wed, Jan 1" */
  normalDateWithWeekday: TLibFormatToken;
  /** Shorter day format @example "Jan 1" */
  shortDate: TLibFormatToken;
  /** Year format string @example "2019" */
  year: TLibFormatToken;
  /** Month format string @example "January" */
  month: TLibFormatToken;
  /** Short month format string @example "Jan" */
  monthShort: TLibFormatToken;
  /** Month with year format string @example "January 2018" */
  monthAndYear: TLibFormatToken;
  /** Month with date format string @example "January 1" */
  monthAndDate: TLibFormatToken;
  /** Weekday format string @example "Wednesday" */
  weekday: TLibFormatToken;
  /** Short weekday format string @example "Wed" */
  weekdayShort: TLibFormatToken;
  /** Day format string @example "1" */
  dayOfMonth: TLibFormatToken;
  /** Hours format string @example "11" */
  hours12h: TLibFormatToken;
  /** Hours format string @example "23" */
  hours24h: TLibFormatToken;
  /** Minutes format string @example "44" */
  minutes: TLibFormatToken;
  /** Seconds format string @example "00" */
  seconds: TLibFormatToken;
  /** Full time localized format string @example "11:44 PM" for US, "23:44" for Europe */
  fullTime: TLibFormatToken;
  /** Not localized full time format string @example "11:44 PM" */
  fullTime12h: TLibFormatToken;
  /** Not localized full time format string @example "23:44" */
  fullTime24h: TLibFormatToken;
  /** Date & time format string with localized time @example "Jan 1, 2018 11:44 PM" */
  fullDateTime: TLibFormatToken;
  /** Not localized date & Time format 12h @example "Jan 1, 2018 11:44 PM" */
  fullDateTime12h: TLibFormatToken;
  /** Not localized date & Time format 24h @example "Jan 1, 2018 23:44" */
  fullDateTime24h: TLibFormatToken;
  /** Localized keyboard input friendly date format @example "02/13/2020 */
  keyboardDate: TLibFormatToken;
  /** Localized keyboard input friendly date/time format @example "02/13/2020 23:44" */
  keyboardDateTime: TLibFormatToken;
  /** Partially localized keyboard input friendly date/time 12h format @example "02/13/2020 11:44 PM" */
  keyboardDateTime12h: TLibFormatToken;
  /** Partially localized keyboard input friendly date/time 24h format @example "02/13/2020 23:44" */
  keyboardDateTime24h: TLibFormatToken;
}

export type Unit =
  | "years"
  | "quarters"
  | "months"
  | "weeks"
  | "days"
  | "hours"
  | "minutes"
  | "seconds"
  | "milliseconds";

export interface IUtils<TDate> {
  formats: DateIOFormats<any>;
  locale?: any;
  moment?: any;
  dayjs?: any;
  /** Name of the library that is used right now */
  lib: string;

  // constructor (options?: { formats?: DateIOFormats, locale?: any, instance?: any });

  date(value?: any): TDate | null;
  toJsDate(value: TDate): Date;
  parseISO(isString: string): TDate;
  toISO(value: TDate): string;
  parse(value: string, format: string): TDate | null;

  getCurrentLocaleCode(): string;
  is12HourCycleInCurrentLocale(): boolean;
  /** Returns user readable format (taking into account localized format tokens), useful to render helper text for input (e.g. placeholder). For luxon always returns empty string. */
  getFormatHelperText(format: string): string;

  isNull(value: TDate | null): boolean;
  isValid(value: any): boolean;
  getDiff(value: TDate, comparing: TDate | string, unit?: Unit): number;
  isEqual(value: any, comparing: any): boolean;

  isSameDay(value: TDate, comparing: TDate): boolean;
  isSameMonth(value: TDate, comparing: TDate): boolean;
  isSameYear(value: TDate, comparing: TDate): boolean;
  isSameHour(value: TDate, comparing: TDate): boolean;

  isAfter(value: TDate, comparing: TDate): boolean;
  isAfterDay(value: TDate, comparing: TDate): boolean;
  isAfterYear(value: TDate, comparing: TDate): boolean;

  isBeforeDay(value: TDate, comparing: TDate): boolean;
  isBeforeYear(value: TDate, comparing: TDate): boolean;
  isBefore(value: TDate, comparing: TDate): boolean;

  isWithinRange(value: TDate, range: [TDate, TDate]): boolean;

  startOfYear(value: TDate): TDate;
  endOfYear(value: TDate): TDate;
  startOfMonth(value: TDate): TDate;
  endOfMonth(value: TDate): TDate;
  startOfWeek(value: TDate): TDate;
  endOfWeek(value: TDate): TDate;

  addSeconds(value: TDate, count: number): TDate;
  addMinutes(value: TDate, count: number): TDate;
  addHours(value: TDate, count: number): TDate;
  addDays(value: TDate, count: number): TDate;
  addWeeks(value: TDate, count: number): TDate;
  addMonths(value: TDate, count: number): TDate;
  addYears(value: TDate, count: number): TDate;

  startOfDay(value: TDate): TDate;
  endOfDay(value: TDate): TDate;

  format(value: TDate, formatKey: keyof DateIOFormats): string;
  formatByString(value: TDate, formatString: string): string;
  formatNumber(numberToFormat: string): string;

  getHours(value: TDate): number;
  setHours(value: TDate, count: number): TDate;

  getMinutes(value: TDate): number;
  setMinutes(value: TDate, count: number): TDate;

  getSeconds(value: TDate): number;
  setSeconds(value: TDate, count: number): TDate;

  getDate(value: TDate): number;
  setDate(value: TDate, count: number): TDate;

  getMonth(value: TDate): number;
  getDaysInMonth(value: TDate): number;
  setMonth(value: TDate, count: number): TDate;
  getNextMonth(value: TDate): TDate;
  getPreviousMonth(value: TDate): TDate;

  getMonthArray(value: TDate): TDate[];

  getYear(value: TDate): number;
  setYear(value: TDate, count: number): TDate;

  mergeDateAndTime(date: TDate, time: TDate): TDate;

  getWeekdays(): string[];
  getWeekArray(date: TDate): TDate[][];
  getYearRange(start: TDate, end: TDate): TDate[];

  /** Allow to customize displaying "am/pm" strings */
  getMeridiemText(ampm: "am" | "pm"): string;
}

For library authors

If you are a library author that exposes date/time management utils or controls you may want to use date-io to interop with the most popular libraries. Here are some instructions on how to use date-fns as an adapter.

1. Install the bindings

First of all, it is required to provide the adapters for your users. We do not recommend installing the date-io directly by the end users, cause it may be easy to mismatch the version. The better way will be to reexport them.

Firstly install all the adapters you want to support and lock the version.

Yes, you will install all of them as dependencies. But every adapter is 50kb unpacked npm module and relieas to the library as for optional peer dependency. It won't be included in user bundle until user will choose which library he want's to use.

{
  "dependencies": {
    "@date-io/date-fns": "x.x.x",
    "@date-io/dayjs": "x.x.x",
    "@date-io/luxon": "x.x.x",
    "@date-io/date-fns-jalali": "x.x.x",
    "@date-io/jalaali": "x.x.x"
  }
}

2. Reexport the bindings

// you-awesome-lib/adapters/date-fns
export { default } from "@date-io/date-fns";

3. Use it for date-time management

Register it using your library context. It may be react context, dependency injection container or any other tool that allows the user to register the used library 1 time.

// react example
import { createMyAdapter } from "your-awesome-lib/adapters/date-fns";

<DateLibProvider adapter={createMyAdapter({ locale: "fr" })}>
  {/* ... */}
</DateLibProvider>;

And use the interface of date-io (or your custom interface).

import { IUtils } from "@date-io/core/IUtils";

function myFunctionInLibrary<TDate>(date: TDate, adapter: IUtils<TDate>) {
  // ...
  const weekArray = adapter.getWeekArray(Date);
  // ...
}

Overriding behavior

It is possible to change or extend the behavior of any adapter by simply inheriting and overriding the base class of utils while saving the same interface.

Let's say you want to override getYear to always return 2007 and getWeekdays to contain only 2 weekends (let's admit that this is what we all desire) you can do the following:

class CustomDateTime extends DayjsUtils implements IUtils<Dayjs> {
  getWeekdays = () => {
    const start = this.dayjs().startOf("week");
    return [0, 1].map((diff) => this.formatByString(start.add(diff, "day"), "dd"));
  };
}

Note: that you will need to do this with every adapter you want to support to be in sync.

Extending behavior

It is possible also to add custom functionality to the adapter, in case the author of date-io doesn't want to add it. To do this create your custom interface that extends IUtils and inherit your adapters both from the base adapter and your custom interface.

// your-awesome-lib/adapters/CustomAdapter
import { IUtils } from "@date-io/core/IUtils";
import DateIODateFnsAdapter from "@date-io/date-fns";

interface CustomUtils<TDate> extends  IUtils<TDate> {
  getDayOfYear(day: TDate): number;
}

interface CustomDateFnsUtils extends DateIODateFnsAdapter implements CustomUtils<Date> {
  getDayOfYear(day: Date): number {
    return getDayOfYear(day);
  }
}

Build system

In some build systems (hello babel) it may be impossible to extend the methods because they are defined as class properties. While it should be standardized already there are still some issues with it. In this case you can use the following workaround:

// you-awesome-lib/adapters/date-fns
import { CustomUtils } from "../CustomUtils";
import getDayOfYear from "date-fns/getDayOfYear";
import DateIODateFnsAdapter from "@date-io/date-fns";

export const createMyAdapter(options) {
  const dateFns = new DateFnsUtils(options)

  const adapter = {
    ...dateFns,

    getWeekArray() {
      const startDate = endOfWeek(adapter.endOfMonth(date), { locale: adapter.locale })
      const extraWeek = adapter.getWeekdays().map((day, index) => adapter.addDays(startDate, index + 1))
      return [...dateFns.getWeekArray(date), extraWeek]
    },

    // ...
  }

  return adapter
}

date-io's People

Contributors

alexfauquette avatar andriyor avatar benmccann avatar c0m1t avatar cbranch101 avatar dependabot-preview[bot] avatar dependabot[bot] avatar dmtrkovalenko avatar dspiteself avatar flaviendelangle avatar hevictor avatar megos avatar mrafei avatar nikita-rudenko avatar palpich avatar paulsavignano avatar philipbulley avatar philipp91 avatar pomadin avatar rcout1nho avatar renovate-bot avatar renovate[bot] avatar sakulstra avatar scriptersugar avatar selenehyun avatar smmoosavi avatar soheilhasankhani avatar t-knapp avatar trevorr avatar winestone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

date-io's Issues

Luxon does not support libInstance

It looks like luxon utils does not support an instance being passed into the constructor like dayjs and moment. I am trying to force everything to be UTC and using libInstance on MuiPickersUtilsProvider is how it is done for dayjs and moment and it is not working for luxon.

I would use Dayjs except typing in the time does not work. Date-fns does not have UTC always support and now Luxon doesn't work either. I was trying not to use moment because it is a monolith but it looks like that is my only option.

CHANGELOG.md is needed

It would be so much better if we had a CHANGELOG.md to make it easier for users and contributors to see precisely what notable changes have been made between each release.

Support for additional methods

We've been discussing the need for just such a library over at Chart.js where our users are complaining about our usage of moment making the download size too large.

I scanned our code and it looks like we would need the following methods in order to use date-io:

luxon?: any
fromMillis(millis): TDate
fromJSDate(jsDate): TDate
TDuration.as(unit: string) or getDiff(TDate, TDate, unit: string)
TDate.startOf(unit: string)
TDate.endOf(unit: string)

Inconsistent getWeekdays between dayjs and other libs

In @date-io/date-fns getWeekdays returns an array of weekdays with respect to user locale:
https://github.com/dmtrKovalenko/date-io/blob/master/packages/date-fns/src/date-fns-utils.ts#L227

In @date-io/dayjs getWeekdays returns an array of weekdays always starting with sunday.
https://github.com/dmtrKovalenko/date-io/blob/master/packages/dayjs/src/dayjs-utils.ts#L209
This happens, because in dayjs `set('day', 0) always yields sunday (source: dayjs docs)

Possible solution to this is to use dayjs().startOf('week'), which results in correct week start for the given locale

Can't resolve 'date-fns/addDays'

Module not found: Can't resolve 'date-fns/addDays' in '/home/tristan/Documents/github/ui/node_modules/@date-io/date-fns/build'

"@date-io/moment": "^1.1.0"

work well with yarn, not with npm

Error: cannot find module @date-io/core/IUtils

Hello!

Nice refactor! I'm encountering the following error after updating.

ERROR in /<truncated>/node_modules/@date-io/moment/build/moment-utils.d.ts(2,24):
TS2307: Cannot find module '@date-io/core/IUtils'.
ERROR in /<truncated>/node_modules/material-ui-pickers/_shared/BasePicker.d.ts(1,24):
TS2307: Cannot find module '@date-io/core/IUtils'.
ERROR in /<truncated>/node_modules/material-ui-pickers/_shared/WithUtils.d.ts(1,24):
TS2307: Cannot find module '@date-io/core/IUtils'.

I was able to workaround the issue by manually installing the core package but I was wondering if perhaps it should be included as a dependency of the moment/date-fns/etc. packages instead?

This is where the problem is (which goes away after installing core):
https://github.com/dmtrKovalenko/date-io/blob/master/packages/moment/src/moment-utils.ts#L2

Mix up of standalone and format tokens for luxon

Hi,

It seems that for @date-iu/luxon you have setup formats without taking into considearion the token difference .

So i have found the following formats in sources

  public yearMonthFormat = "MMMM yyyy";
  public dateFormat = "LLLL dd";

I would expect the formats

  public yearMonthFormat = "LLLL yyyy"; // standalone token for month as it has no correlation with a day
  public dateFormat = "MMMM dd"; // format token for month as it should correlate with day

Or am I wrong in my expectations?

How to localize dayjs?

Hi,

I want to localize dayjs as it's lib I use in project. I tried:
<MuiPickersUtilsProvider utils={DayJsUtils} locale={'de'}>
but no lack.

I tried also (similar to moment example):

import { MuiPickersUtilsProvider } from 'material-ui-pickers'
import dayjs from 'dayjs'
import 'dayjs/locale/de'
import DayJsUtils from '@date-io/dayjs'

dayjs.locale('de')

in this case date picker is still not localized (week days, month names).

Any hint how should I do it?

Thanks in advice!

Importing @date-io/date-fns breaks the build

I recently updated to 1.3.8 and just importing it into and app which is compiled by webpack breaks it. The compilation passes but the application fails silently.

import DateFnsUtils from "@date-io/date-fns";

// This line is never reached:
console.error(DateFnsUtils);

Document usage from a library perspective

It looks like this is a great way to avoid requiring a specific date lib as a dep/peer dep.

material-ui-pickers is implemented with something like:

import MomentUtils from '@date-io/moment';
import DateFnsUtils from '@date-io/date-fns';
import LuxonUtils from '@date-io/luxon';
import { MuiPickersUtilsProvider } from '@material-ui/pickers';

function App() {
  return (
    <MuiPickersUtilsProvider utils={DateFnsUtils}>
      <Root />
    </MuiPickersUtilsProvider>
  );
}

render(<App />, document.querySelector('#app'));

Is there any way to auto-register the various utils to global to avoid requiring context? Or is this pattern with react context the best we can do?

Issue

The best way for other libraries to work with this library should be documented.

Fix "moment" import in <moment-utils.d.ts>

Hi, fix please:

import * as defaultMoment from "moment";

instead

import defaultMoment from "moment";

Actually I'm doing it manually because the app crash when try compile.

How do add additional format

Hi,

The date format listed in DateIOFormats hasnt got one I need. I need dd/MM/yyyy or similar. How do I implement it?

So if I use

<MuiPickersUtilsProvider utils={DateFnsUtils}>
            <React.Fragment>
                <FormControl fullWidth={full}>
                    <KeyboardDateTimePicker 
                        value={value ? parse(value, dateFormat, new Date()) : null}
                        placeholder={placeholder}
                        format={"dd-MM-yyyy"}
                        onChange={(date) => {
                        }}
                    />
                </FormControl>
            </React.Fragment>
</MuiPickersUtilsProvider>

I get RangeError: Format string contains an unescaped latin alphabet character n`` error.
Only works if I use fullDate or one of the format listed in DateIOFormats

<MuiPickersUtilsProvider utils={DateFnsUtils}>
            <React.Fragment>
                <FormControl fullWidth={full}>
                    <KeyboardDateTimePicker 
                        value={value ? parse(value, dateFormat, new Date()) : null}
                        placeholder={placeholder}
                        format="fullDate"
                        onChange={(date) => {
                        }}
                    />
                </FormControl>
            </React.Fragment>
</MuiPickersUtilsProvider>

Any idea?

Date library peer dependencies

Would it be possible to either relax the version constraint for date library peer dependencies, or publish more often?

The current version of @date-io/date-fns has a peer dependency for [email protected] while the latest version is 2.4.1.

It seems to be a pretty constant issue that this peer dependency isn't met when you strive to keep your dependencies up to date.

Mix up of standalone and format tokens for date-fns

Environment

Tech Version
@material-ui/pickers ^3.2.0
material-ui ^4.2.0
React ^16.8.6
date-fns 2.0.0-beta.2

Steps to reproduce

  1. Basic setup for date-fns
  2. Open Datepicker and choose date, e.g. July 24, 2019

Expected behavior

The translation in the Datepicker header should be in nominative: červenec

Actual behavior

The translation in the Datepicker header is in genitive: července

Screen Shot 2019-07-24 at 09 05 39

Live example

https://codesandbox.io/s/material-ui-pickers-usage-demo-29nmv

I found out that getCalendarHeaderText is always called with MMMM yyyy which is formatted and it should be instead standalone LLLL yyyy shouldn't it?

// date-fns/src/date-fns-utils.ts
// this.yearMonthFormat = "MMMM yyyy";

DateFnsUtils.prototype.getCalendarHeaderText = function (date) {
  return format(date, this.yearMonthFormat, { locale: this.locale });
};

Other formats could be fixed as well. I switched the order of month and day to match my language (Czech or Slovak), not sure if it is applicable for other languages as well 🤔🤷🏻‍♂️

format Bad Good
yearMonthFormat MMMM yyyy LLLL yyyy
dateTime12hFormat MMMM do hh:mm aaaa do MMMM hh:mm aaaa
dateTime24hFormat MMMM do HH:mm do MMMM HH:mm
dateFormat MMMM do do MMMM

Cannot find module '@date-io/core/IUtils'

Hello everyone,

I'm using the latest version available on npm, it's 1.3.6. As stated in #42 it should be fixed, but isn't.
tsconfig.json has the following in it:

{
  "compilerOptions": {
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true
  }
}

Full error (with stripped paths)

......./node_modules/@date-io/moment/build/moment-utils.d.ts
TypeScript error in ....../node_modules/@date-io/moment/build/moment-utils.d.ts(2,24):
Cannot find module '@date-io/core/IUtils'.  TS2307

    1 | import defaultMoment from "moment";
  > 2 | import { IUtils } from "@date-io/core/IUtils";
      |                        ^
    3 | interface Opts {
    4 |     locale?: string;
    5 |     instance?: typeof defaultMoment;

Versions:

    "@date-io/moment": "^1.3.6",
    "@material-ui/core": "^4.0.2",
    "@material-ui/pickers": "^3.1.0",
    "moment": "^2.24.0",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "tslint": "^5.17.0",
    "tslint-react": "^4.0.0",
    "typescript": "^3.5.1"

Cheers

Wrong weekdays with moment.js

var MomentUtils = require("@date-io/moment");

const moment = new MomentUtils({'locale': 'ru'});
console.log(moment.getWeekdays());

Expected:

["пн", "вт", "ср", "чт", "пт", "сб", "вс"]

Actual:

["вс", "пн", "вт", "ср", "чт", "пт", "сб"]

https://runkit.com/embed/k6vhvc5yc9df

Unix timestamp support

Adding getting a time instance as Unix timestamp. I can add the functionality to all libs and send a PR.

TypeScript definition issue with moment import -

When compiling with TypeScript, I receive the following error:

Module '"/<truncated>/moment/moment"' has no default export

The moment import appears to be written as import defaultMoment from "moment", but typically in TypeScript this is written as import * as moment from "moment", since moment does not use an ES6 style default export.

Add support for js-joda

js-joda is an immutable date and time library which is often mentioned alongside the other alternatives to moment.js.

It would be great to include and would allow easy use with Material-UI Pickers.

Make internal format function always use this.format

In order to make it easy override format behavior with class inheritance. Like for date-fns-tz

class DateFnsTzUtils {
  format(date, formatString) {
    return formatTz(date, formatString, {
      timeZone: "America/New_York",
      locale: this.locale
    });
  }
}

Replace methods with arrow class properties

Im am using date-ioin combination with @material-ui/pickers and @date-io/date-fns. I came across some error which is caused by the class based implementation of https://github.com/dmtrKovalenko/date-io/blob/master/packages/date-fns/src/date-fns-utils.ts

Here is what I was trying to do:

import { useUtils } from '@material-ui/pickers';

const MyComponent = () => {
    const { isSameDay, isValid } = useUtils();

    isValid(someDate);
}

The error occured in the isValid call, because it uses internally this.date() and I suspect that this is not the right context when the method was destructured.

Maybe that this usage is not what you intended. But working with a factory function could lead to a better developer expierience.

Example:

// ...

const ensureDate = date(value?: any) {
    if (typeof value === "undefined") {
        return new Date();
    }

    if (value === null) {
        return null;
    }

    return new Date(value);
}

// ...

export default function createDateFnsAdapter(locale): IUtils<Date> {
    // ...
    const getDatePickerHeaderText = (date: Date) => format(date, "EEE, MMM d", { locale });
    const isValid = (value: any) => isValid(ensureDate(value));
    // ...

    return {
        // ...
        getDatePickerHeaderText,
        isValid,
        // ...
    }
}

moment-timezone

Is there a way to incorporate moment-timezone with this? Particularly being able to set the default timezone?

npm install fails

On NPM install I`am getting following error:
npm ERR! code E404
npm ERR! 404 Not Found: @date-io/moment@latest

Any changes here? How I can install moment or any other utils?

Regards
Max

conflicts between date-fns and core in new 1.3.12 version?

my project pulled new npm package #v1.3.12 and received the following upon build

[Container] 2019/12/03 16:32:10 Running command npm install 
npm WARN deprecated [email protected]: One of your dependencies needs to upgrade to fsevents v2: 1) Proper nodejs v10+ support 2) No more fetching binaries from AWS, smaller package size 
npm WARN deprecated [email protected]: core-js@<3.0 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3. 
npm WARN deprecated [email protected]: core-js@<3.0 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3. 
npm WARN deprecated [email protected]: use String.prototype.padStart() 
npm ERR! code ETARGET 
npm ERR! notarget No matching version found for @date-io/core@^1.3.12 
npm ERR! notarget In most cases you or one of your dependencies are requesting 
npm ERR! notarget a package version that doesn't exist. 
npm ERR! notarget  
npm ERR! notarget It was specified as a dependency of '@date-io/date-fns' 
npm ERR! notarget  
 
npm ERR! A complete log of this run can be found in: 
npm ERR!     /root/.npm/_logs/2019-12-03T16_32_20_969Z-debug.log 

after fixing it back to 1.3.11 it worked

my dependencies:

    "@date-io/date-fns": "^1.3.11",
    "@material-ui/pickers": "^3.2.6",
    "axios": "^0.18.0",
    "date-fns": "^2.2.1",
    "jss-rtl": "^0.2.3",
    "prop-types": "^15.7.2",
    "react-select": "^3.0.8",
    "styled-components": "^4.3.2",
    "yup": "^0.27.0"

Thanks

Module ''date-fns/locale/en-US'' has no default export

I'm getting the error Module ''date-fns/locale/en-US'' has no default export at node_modules/@date-io/date-fns/build/date-fns-utils.d.ts.

// tsconfig.json
{
  "compilerOptions": {
    "baseUrl": ".",
    "jsx": "react",
    "lib": ["esnext", "dom"],
    "module": "esnext",
    "moduleResolution": "node",
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "sourceMap": true,
    "strictNullChecks": true,
    "target": "es5"
  },
  "exclude": ["node_modules", "**/*.spec.ts"]
}

Environment:
@date-io/date-fns: "0.0.2"
date-fns": "2.0.0-alpha.25"

v1 breaks material-ui-pickers

When updating from v0.0.2 to 1.0.0 a once working app now errors:

material-ui-pickers.esm.js:1386 Uncaught TypeError: _this.props.utils.getStartOfMonth is not a function
    at new Calendar (material-ui-pickers.esm.js:1386)
    at constructClassInstance (react-dom.development.js:13082)
    at updateClassComponent (react-dom.development.js:14978)
    at beginWork (react-dom.development.js:15845)
    at performUnitOfWork (react-dom.development.js:18879)
    at workLoop (react-dom.development.js:18920)
    at HTMLUnknownElement.callCallback (react-dom.development.js:147)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:196)
    at invokeGuardedCallback (react-dom.development.js:250)
    at replayUnitOfWork (react-dom.development.js:18127)
    at renderRoot (react-dom.development.js:19038)
    at performWorkOnRoot (react-dom.development.js:19941)
    at performWork (react-dom.development.js:19851)
    at performSyncWork (react-dom.development.js:19825)
    at interactiveUpdates$1 (react-dom.development.js:20113)
    at interactiveUpdates (react-dom.development.js:2267)
    at dispatchInteractiveEvent (react-dom.development.js:5081)

Make peerDependency more flexible

Eg. for date-fns.

  "peerDependencies": {
    "date-fns": "2.6.0"
  },

It would be more convenient for consumers to have a range such as ^2.6.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.