
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
A javascript common use date utilities and compatible with typescript.
npm install one-day --save
yarn add one-day
calcDate(date: Date, calcType: 'add' | 'subtract', unitType: OpUnitType, value: number): Dayjs
Add or Subtract date by unit type.
Example
console.log(calcDate(new Date(date), 'add', 'day', 10).format('DD-MMM-YYYY'));
//expected output: "15-Apr-2020"
dayToTime(day: number, type?: 'ms' | 's' | 'm' | 'h'): number
Convert from day(s) to millisecond, second, minute and hour.
Example
console.log(dayToTime(1, 'h'));
//expected output: 24
fromNow(date?: ConfigType): string
Returns the string of relative time from now
Example
console.log(fromNow(new Date()));
// expected output: "a second ago"
getFirstDayOfMonth(date: Date, type: 'Previous' | 'Current' | 'Next'): Dayjs
Get the first day of the month.
Example
const date = '2020-04-05';
const format = 'DD-MMM-YYYY';
console.log(getFirstDayOfMonth(new Date(date), 'Previous').format(format));
// expected output: '01-Mar-2020'
console.log(getFirstDayOfMonth(new Date(date), 'Current').format(format));
// expected output: '01-Apr-2020'
// Next month
console.log(getFirstDayOfMonth(new Date(date), 'Next').format(format));
// expected output: '01-May-2020'
getLastDayOfMonth(date: Date, type: 'Previous' | 'Current' | 'Next'): Dayjs
Get the last day of the month.
Example
const date = '2020-04-05';
const format = 'DD-MMM-YYYY';
console.log(getLastDayOfMonth(new Date(date), 'Previous').format(format));
// expected output: '31-Mar-2020'
console.log(getLastDayOfMonth(new Date(date), 'Current').format(format));
// expected output: '30-Apr-2020'
console.log(getLastDayOfMonth(new Date(date), 'Next').format(format));
// expected output: '31-May-2020'
previousMonth(format?: string);
Get the first and last day of previous month.
Example
// '2020-04-05';
console.log(previousMonth());
// expected output: { from: '01-Mar-2020', to: '31-Mar-2020' }
previousWeek(format?: string);
Get the first and last day of previous week.
Example
// '2020-05-19';
console.log(previousWeek());
// expected output: { from: '10-May-2020', to: '16-May-2020' }
previousWeek(format?: string);
Gets the quarter of the year.
Example
// '2020-05-19';
// Get Current Quarter
quarter.current();
// expected output: { from: '01-Apr-2020', to: '30-Jun-2020' }
// Get Previous Quarter
quarter.previous();
// expected output: { from: '01-Jan-2020', to: '31-Mar-2020' }
// Get Specific Quarter
quarter.quarter(1);
// expected output: { from: '01-Jan-2020', to: '31-Mar-2020' }
smartTZ(utc: string, options?: smartTZOptions): string | Dayjs
Convert UTC date to specific time zone.
Example
const format = 'DD-MM-YYYY HH:mm:ss';
const UTCString = '2019-07-25T16:00:00.48Z';
smartTZ(UTCString, { timezone: 'Asia/Jakarta', format: format });
// expected output: 25-07-2019 23:00:00
thisMonth((format?: string));
Get the first and last day of current month.
Example
// 2020-05-19
thisMonth();
// expected output: { from: '01-May-2020', to: '31-May-2020' }
thisWeek((format?: string));
Get the first and last day of current week.
Example
// 2020-05-19
thisWeek();
// expected output: { from: '17-May-2020', to: '23-May-2020' }
thisYear((format?: string));
Get the first and last day of current year.
Example
// 2020-05-19
thisYear();
// expected output: { from: '01-Jan-2020', to: '31-Dec-2020' }
today((format?: string));
Get today date.
Example
// 2020-05-19
today();
// expected output: { from: '19-May-2020', to: '19-May-2020' }
today((format?: string));
Get yesterday date.
Example
// 2020-05-19
yesterday();
// expected output: { from: '18-May-2020', to: '18-May-2020' }
FAQs
A javascript common use date utilities and compatible with typescript.
We found that one-day-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.