
Security News
Another Round of TEA Protocol Spam Floods npm, But It’s Not a Worm
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.
@woocommerce/date
Advanced tools
A collection of utilities to display and work with date values.
Install the module
pnpm install @woocommerce/date --save
This package assumes that your code will run in an ES2015+ environment. If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using core-js or @babel/polyfill will add support for these methods. Learn more about it in Babel docs.
The date package makes use of the global window.wcSettings.timeZone. If a timezone is set, the current and last periods will be converted from your browser's timezone to the store timezone. If none is set, these periods will be based on your browser's timezone.
stringAdds timestamp to a string date.
DateValueGet a DateValue object for a period described by a period, compare value, and start/end dates, for custom dates.
ObjectMemoized internal logic of getDateParamsFromQuery().
DateParamsAdd default date-related parameters to a query object
ObjectMemoized internal logic of getCurrentDates().
ObjectGet Date Value Objects for a primary and secondary date range
numberCalculates the date difference between two dates. Used in calculating a matching date for previous period.
ObjectGet the previous date for either the previous period of year.
Object | nullConvert a string to Moment object
stringGiven two dates, derive a string representation
stringGets the current time in the store time zone if set.
DateValueGet a DateValue object for a period prior to the current period.
DateValueGet a DateValue object for a curent period. The period begins on the first day of the period, and ends on the current day.
ArrayReturns the allowed selectable intervals for a specific query.
stringReturns the current interval to use.
stringReturns the current chart type to use.
stringReturns date formats for the current interval.
stringReturns d3 date formats for the current interval. See https://github.com/d3/d3-time-format for chart formats.
stringReturns php date formats for the current interval. See see https://www.php.net/manual/en/datetime.format.php.
Gutenberg's moment instance is loaded with i18n values, which are PHP date formats, ie 'LLL: "F j, Y g:i a"'. Override those with translations of moment style js formats.
ObjectValidate text input supplied for a date range.
ObjectDateValue Object
ObjectDateParams Object
ObjectstringAdds timestamp to a string date.
Kind: global constant
Returns: string - - String date with timestamp attached.
| Param | Type | Description |
|---|---|---|
| date | moment.Moment | Date as a moment object. |
| timeOfDay | string | Either start, now or end of the day. |
DateValueGet a DateValue object for a period described by a period, compare value, and start/end dates, for custom dates.
Kind: global constant
Returns: DateValue - - DateValue data about the selected period
| Param | Type | Description |
|---|---|---|
| period | string | the chosen period |
| compare | string | previous_period or previous_year |
| [after] | Object | after date if custom period |
| [before] | Object | before date if custom period |
ObjectMemoized internal logic of getDateParamsFromQuery().
Kind: global constant
Returns: Object - - date parameters derived from query parameters with added defaults
| Param | Type | Description |
|---|---|---|
| period | string | period value, ie last_week |
| compare | string | compare value, ie previous_year |
| after | string | date in iso date format, ie 2018-07-03 |
| before | string | date in iso date format, ie 2018-07-03 |
| defaultDateRange | string | the store's default date range |
DateParamsAdd default date-related parameters to a query object
Kind: global constant
Returns: DateParams - - date parameters derived from query parameters with added defaults
| Param | Type | Description |
|---|---|---|
| query | Object | query object |
| query.period | string | period value, ie last_week |
| query.compare | string | compare value, ie previous_year |
| query.after | string | date in iso date format, ie 2018-07-03 |
| query.before | string | date in iso date format, ie 2018-07-03 |
| defaultDateRange | string | the store's default date range |
ObjectMemoized internal logic of getCurrentDates().
Kind: global constant
Returns: Object - - Primary and secondary DateValue objects
| Param | Type | Description |
|---|---|---|
| period | string | period value, ie last_week |
| compare | string | compare value, ie previous_year |
| primaryStart | Object | primary query start DateTime, in Moment instance. |
| primaryEnd | Object | primary query start DateTime, in Moment instance. |
| secondaryStart | Object | primary query start DateTime, in Moment instance. |
| secondaryEnd | Object | primary query start DateTime, in Moment instance. |
ObjectGet Date Value Objects for a primary and secondary date range
Kind: global constant
Returns: Object - - Primary and secondary DateValue objects
| Param | Type | Description |
|---|---|---|
| query | Object | query object |
| query.period | string | period value, ie last_week |
| query.compare | string | compare value, ie previous_year |
| query.after | string | date in iso date format, ie 2018-07-03 |
| query.before | string | date in iso date format, ie 2018-07-03 |
| defaultDateRange | string | the store's default date range |
numberCalculates the date difference between two dates. Used in calculating a matching date for previous period.
Kind: global constant
Returns: number - - Difference in days.
| Param | Type | Description |
|---|---|---|
| date | string | Date to compare |
| date2 | string | Seconary date to compare |
ObjectGet the previous date for either the previous period of year.
Kind: global constant
Returns: Object - - Calculated date
| Param | Type | Description |
|---|---|---|
| date | string | Base date |
| date1 | string | primary start |
| date2 | string | secondary start |
| compare | string | previous_period or previous_year |
| interval | string | interval |
Object | nullConvert a string to Moment object
Kind: global function
Returns: Object | null - - Moment object representing given string
| Param | Type | Description |
|---|---|---|
| format | string | localized date string format |
| str | string | date string |
stringGiven two dates, derive a string representation
Kind: global function
Returns: string - - text value for the supplied date range
| Param | Type | Description |
|---|---|---|
| after | Object | start date |
| before | Object | end date |
stringGets the current time in the store time zone if set.
Kind: global function
Returns: string - - Datetime string.
DateValueGet a DateValue object for a period prior to the current period.
Kind: global function
Returns: DateValue - - DateValue data about the selected period
| Param | Type | Description |
|---|---|---|
| period | string | the chosen period |
| compare | string | previous_period or previous_year |
DateValueGet a DateValue object for a curent period. The period begins on the first day of the period, and ends on the current day.
Kind: global function
Returns: DateValue - - DateValue data about the selected period
| Param | Type | Description |
|---|---|---|
| period | string | the chosen period |
| compare | string | previous_period or previous_year |
ArrayReturns the allowed selectable intervals for a specific query.
Kind: global function
Returns: Array - Array containing allowed intervals.
| Param | Type | Description |
|---|---|---|
| query | Object | Current query |
| defaultDateRange | string | the store's default date range |
stringReturns the current interval to use.
Kind: global function
Returns: string - Current interval.
| Param | Type | Description |
|---|---|---|
| query | Object | Current query |
| defaultDateRange | string | the store's default date range |
stringReturns the current chart type to use.
Kind: global function
Returns: string - Current chart type.
| Param | Type | Description |
|---|---|---|
| query | Object | Current query |
| query.chartType | string |
stringReturns date formats for the current interval.
Kind: global function
Returns: string - Current interval.
| Param | Type | Description |
|---|---|---|
| interval | string | Interval to get date formats for. |
| [ticks] | number | Number of ticks the axis will have. |
| [option] | Object | Options |
| [option.type] | string | Date format type, d3 or php, defaults to d3. |
stringReturns d3 date formats for the current interval. See https://github.com/d3/d3-time-format for chart formats.
Kind: global function
Returns: string - Current interval.
| Param | Type | Description |
|---|---|---|
| interval | string | Interval to get date formats for. |
| [ticks] | number | Number of ticks the axis will have. |
stringReturns php date formats for the current interval. See see https://www.php.net/manual/en/datetime.format.php.
Kind: global function
Returns: string - Current interval.
| Param | Type | Description |
|---|---|---|
| interval | string | Interval to get date formats for. |
| [ticks] | number | Number of ticks the axis will have. |
Gutenberg's moment instance is loaded with i18n values, which are PHP date formats, ie 'LLL: "F j, Y g:i a"'. Override those with translations of moment style js formats.
Kind: global function
| Param | Type | Description |
|---|---|---|
| config | Object | Locale config object, from store settings. |
| config.userLocale | string | |
| config.weekdaysShort | Array |
ObjectValidate text input supplied for a date range.
Kind: global function
Returns: Object - validatedDate - validated date object
| Param | Type | Description |
|---|---|---|
| type | string | Designate beginning or end of range, eg before or after. |
| value | string | User input value |
| [before] | Object | null | If already designated, the before date parameter |
| [after] | Object | null | If already designated, the after date parameter |
| format | string | The expected date format in a user's locale |
ObjectDateValue Object
Kind: global typedef Properties
| Name | Type | Description |
|---|---|---|
| label | string | The translated value of the period. |
| range | string | The human readable value of a date range. |
| after | moment.Moment | Start of the date range. |
| before | moment.Moment | End of the date range. |
ObjectDateParams Object
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| after | moment.Moment | null | If the period supplied is "custom", this is the after date |
| before | moment.Moment | null | If the period supplied is "custom", this is the before date |
Properties
| Name | Type | Description |
|---|---|---|
| period | string | period value, ie last_week |
| compare | string | compare valuer, ie previous_year |
ObjectKind: global typedef Properties
| Name | Type | Description |
|---|---|---|
| date | Object | null | A resulting Moment date object or null, if invalid |
| error | string | An optional error message if date is invalid |
FAQs
WooCommerce date utilities.
The npm package @woocommerce/date receives a total of 3,070 weekly downloads. As such, @woocommerce/date popularity was classified as popular.
We found that @woocommerce/date demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 20 open source maintainers 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
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.

Security News
PyPI adds Trusted Publishing support for GitLab Self-Managed as adoption reaches 25% of uploads

Research
/Security News
A malicious Chrome extension posing as an Ethereum wallet steals seed phrases by encoding them into Sui transactions, enabling full wallet takeover.