Skip to content

Latest commit

 

History

History
98 lines (70 loc) · 3.98 KB

README.md

File metadata and controls

98 lines (70 loc) · 3.98 KB

utc-date

Generate UTC date with various offsets


MIT License

Returns a JavaScript date object using the UTC timezone with optional offsets to adjust the year, month, or date.

Table of contents

Usage

import { utcDate } from 'nodemod/dist/utc-date/index.js';

(async () => {
  /** Assuming today's date is '2020-02-02' */
  const defaultUTCDate = await utcDate();
  const defaultUTCDateWithOffsets = await utcDate({
    offset: {
      year: 2,
      month: 1,
      day: 0,
    },
  });
  const specifiedUTCDate = await utcDate({
    startDate: '2030-03-02',
  });
  
  defaultUTCDate === new Date('2020-02-02T00:00:00.000Z'); /** true */
  defaultUTCDateWithOffsets === new Date('2022-03-02T00:00:00.000Z'); /** true */
  specifiedUTCDate === new Date('2030-03-02T00:00:00.000Z'); /** true */
})();

API Reference

UTCDateParams

  • offsets <?Object> Optional offset values when returning a JavaScript Date object using the UTC timezone.
    • year <?number> Optional offset to adjust the year.
    • month <?number> Optional offset to adjust the month.
    • day <?number> Optional offset to adjust the day.
  • startDate <?string|?number|?Date> Optional starting date. Defaults to today's date if it is not given.

utcDate([UTCDateParams])

utcDateSync([UTCDateParams])

This methods works the same as utcDate([UTCDateParams]) except that this is the synchronous version.

License

MIT License © Rong Sen Ng