Skip to content

Commit

Permalink
Allow date value as number
Browse files Browse the repository at this point in the history
  • Loading branch information
manzoorwanijk committed Dec 4, 2024
1 parent 73c5a26 commit a1c9a0f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions packages/date/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ _Related_
_Parameters_

- _dateFormat_ `string`: PHP-style formatting string. See php.net/date.
- _dateValue_ `Moment | Date | string`: Date object or string, parsable by moment.js.
- _dateValue_ `Moment | Date | string | number`: Date object or string, parsable by moment.js.
- _timezone_ `string`: Timezone to output result in or a UTC offset. Defaults to timezone from site.

_Returns_
Expand All @@ -49,7 +49,7 @@ _Related_
_Parameters_

- _dateFormat_ `string`: PHP-style formatting string. See php.net/date.
- _dateValue_ `Moment | Date | string`: Date object or string, parsable by moment.js.
- _dateValue_ `Moment | Date | string | number`: Date object or string, parsable by moment.js.
- _timezone_ `string | number | boolean`: Timezone to output result in or a UTC offset. Defaults to timezone from site. Notice: `boolean` is effectively deprecated, but still supported for backward compatibility reasons.

_Returns_
Expand All @@ -63,7 +63,7 @@ Formats a date. Does not alter the date's timezone.
_Parameters_

- _dateFormat_ `string`: PHP-style formatting string. See php.net/date.
- _dateValue_ `Moment | Date | string`: Date object or string, parsable by moment.js.
- _dateValue_ `Moment | Date | string | number`: Date object or string, parsable by moment.js.

_Returns_

Expand Down Expand Up @@ -96,7 +96,7 @@ Formats a date (like `date()` in PHP), in the UTC timezone.
_Parameters_

- _dateFormat_ `string`: PHP-style formatting string. See php.net/date.
- _dateValue_ `Moment | Date | string`: Date object or string, parsable by moment.js.
- _dateValue_ `Moment | Date | string | number`: Date object or string, parsable by moment.js.

_Returns_

Expand All @@ -109,7 +109,7 @@ Formats a date (like `wp_date()` in PHP), translating it into site's locale and
_Parameters_

- _dateFormat_ `string`: PHP-style formatting string. See php.net/date.
- _dateValue_ `Moment | Date | string`: Date object or string, parsable by moment.js.
- _dateValue_ `Moment | Date | string | number`: Date object or string, parsable by moment.js.

_Returns_

Expand All @@ -134,7 +134,7 @@ Check whether a date is considered in the future according to the WordPress sett

_Parameters_

- _dateValue_ `string`: Date String or Date object in the Defined WP Timezone.
- _dateValue_ `Date | string`: Date String or Date object in the Defined WP Timezone.

_Returns_

Expand Down
14 changes: 7 additions & 7 deletions packages/date/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ const formatMap = {
*/
export function format(
dateFormat: string,
dateValue: Moment | Date | string = new Date()
dateValue: Moment | Date | string | number = new Date()
) {
let i, char;
const newFormat = [];
Expand Down Expand Up @@ -455,7 +455,7 @@ export function format(
*/
export function date(
dateFormat: string,
dateValue: Moment | Date | string = new Date(),
dateValue: Moment | Date | string | number = new Date(),
timezone?: string
) {
const dateMoment = buildMoment( dateValue, timezone );
Expand All @@ -474,7 +474,7 @@ export function date(
*/
export function gmdate(
dateFormat: string,
dateValue: Moment | Date | string = new Date()
dateValue: Moment | Date | string | number = new Date()
) {
const dateMoment = momentLib( dateValue ).utc();
return format( dateFormat, dateMoment );
Expand Down Expand Up @@ -503,7 +503,7 @@ export function gmdate(
*/
export function dateI18n(
dateFormat: string,
dateValue: Moment | Date | string = new Date(),
dateValue: Moment | Date | string | number = new Date(),
timezone?: string | number | boolean
) {
if ( true === timezone ) {
Expand Down Expand Up @@ -532,7 +532,7 @@ export function dateI18n(
*/
export function gmdateI18n(
dateFormat: string,
dateValue: Moment | Date | string = new Date()
dateValue: Moment | Date | string | number = new Date()
) {
const dateMoment = momentLib( dateValue ).utc();
dateMoment.locale( settings.l10n.locale );
Expand All @@ -546,7 +546,7 @@ export function gmdateI18n(
*
* @return Is in the future.
*/
export function isInTheFuture( dateValue: string ) {
export function isInTheFuture( dateValue: Date | string ) {
const now = momentLib.tz( WP_ZONE );
const momentObject = momentLib.tz( dateValue, WP_ZONE );

Expand Down Expand Up @@ -600,7 +600,7 @@ export function humanTimeDiff(
* @return A moment instance.
*/
function buildMoment(
dateValue?: Moment | Date | string,
dateValue?: Moment | Date | string | number,
timezone: string | number = ''
) {
const dateMoment = momentLib( dateValue );
Expand Down

0 comments on commit a1c9a0f

Please sign in to comment.