Datetime
Clinux UI provides a set of useful functions to manipulate JS Date easily in most use cases, using the date-fns lib.
Overview
declare const isMoreThan2Days: (date: string) => boolean;
declare const getFormattedDate: (date: string) => string;
declare const getRawDate: (date: string) => string;
declare const getFormattedDateTime: (date: string) => string | undefined;
declare const getFormattedPrettyDateTime: (date: string) => string;
declare const getFormattedTime: (date: string) => string;
declare const getFormattedYearFromNow: () => string;
declare const isDateAfter: (date: string, after: string) => boolean;
declare const isDateBetween: (
date: string,
start: string,
end: string,
) => boolean;
declare const isValidDate: (date: string) => boolean;
declare const isValidTime: (date: string) => boolean;
declare const getIsoString: (value: string) => string;
declare const getYear: () => number;
declare const isValidBornDate: (date: string) => boolean;isMoreThan2Days
Provides a boolean wich show if the date to compare is more than 2 days compared from today.
import { isMoreThan2Days } from '@/utils';
// today is 2020-01-31
const date = '2020-02-01';
console.log(isMoreThan2Days(date));
// falseimport { isMoreThan2Days } from '@/utils';
// today is 2020-01-31
const date = '2020-02-04';
console.log(isMoreThan2Days(date));
// truegetFormattedDate
Provides a DD/MM/YYYY date.
import { getFormattedDate } from '@/utils';
const date = '2020-02-01';
console.log(getFormattedDate(date));
// 01/02/2020getRawDate
Provides a YYYY-MM-DD date.
import { getRawDate } from '@/utils';
const date = '01/02/2020';
console.log(getRawDate(date));
// 2020-02-01getFormattedDateTime
Provides a DD/MM/YYYY [às] HH:mm date and time.
import { getFormattedDateTime } from '@/utils';
const date = '2020-02-01 04:00:00';
console.log(getFormattedDateTime(date));
// 01/02/2020 às 04:00getFormattedPrettyDateTime
Provides a pretty date and time.
import { getFormattedPrettyDateTime } from '@/utils';
// today is 2020-01-31
const date = '2020-02-01 04:00:00';
console.log(getFormattedPrettyDateTime(date));
// Há um dia atrásgetFormattedTime
Provides a HH:mm time.
import { getFormattedTime } from '@/utils';
const hour = '04:00:00';
console.log(getFormattedTime(hour));
// 04:00getFormattedYearFromNow
Provides the current year.
import { getFormattedYearFromNow } from '@/utils';
// Today is 2020-02-01
console.log(getFormattedYearFromNow());
// 2020isDateAfter
Provides a boolean to show if the date and date after is true or false.
import { isDateAfter } from '@/utils';
const date = '2020-02-01';
const after = '2020-01-31';
console.log(isDateAfter(date, after));
// falseimport { isDateAfter } from '@/utils';
const date = '2020-02-01';
const after = '2020-02-32';
console.log(isDateAfter(date, after));
// trueisDateBetween
Provides a boolean to show if the date is between 2 dates.
import { isDateBetween } from '@/utils';
const date = '2020-02-01';
const start = '2020-01-30';
const end = '2020-01-31';
console.log(isDateBetween(date, start, end));
// falseimport { isDateBetween } from '@/utils';
const date = '2020-02-01';
const start = '2020-01-31';
const end = '2020-02-02';
console.log(isDateBetween(date, start, end));
// trueisValidDate
Provides a boolean to show if the date informed is valid.
import { isValidDate } from '@/utils';
const date = '2020-02-01';
console.log(isValidDate(date));
// trueimport { isValidDate } from '@/utils';
const date = '202320-02?01';
console.log(isValidDate(date));
// falseisValidTime
Provides a boolean to show if the time informed is valid.
import { isValidTime } from '@/utils';
const time = '04:00:00';
console.log(isValidTime(time));
// trueimport { isValidTime } from '@/utils';
const time = 'abs:01';
console.log(isValidTime(time));
// falsegetIsoString
Provides a ISO string of date.
import { getIsoString } from '@/utils';
const time = '2020-01-31 04:00:00';
console.log(getIsoString(time));
// 2020-01-31T04:00:00ZgetYear
Provides a current year.
import { getYear } from '@/utils';
// Today is 2020-01-01
console.log(getYear());
// 2020isValidBornDate
Provides a boolean to show if the date informed is a valid born date. The rule is the date must me greater than 31/12/1899 and lower than now.
import { isValidBornDate } from '@/utils';
const date = '2020-01-01';
console.log(isValidBornDate(date));
// trueimport { isValidBornDate } from '@/utils';
const date = '1100-01-01';
console.log(isValidBornDate(date));
// falseimport { isValidBornDate } from '@/utils';
const date = '2900-01-01';
console.log(isValidBornDate(date));
// false