Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Export formatDate function #1286

Merged
merged 1 commit into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/dates/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

---

## [Unreleased]

- Export the `formatDate` function so it can be used by other packages / projects, e.g. in `@shopify/react-i18n`

## [0.2.13] - 2020-02-07

- Fixes the memory leak that was introduced in v0.1.27 when server-side rendering ([#1277](https://github.com/Shopify/quilt/pull/1277))
Expand Down
17 changes: 17 additions & 0 deletions packages/dates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ const timeZone2 = 'America/Toronto';
const newDate = applyTimeZoneOffset(date, timeZone1, timeZone2);
```

### `formatDate`

Takes in a date object and two additional parameters, the locale and an optional options object. Returns a new date string with the applied locale and options.

```ts
import {formatDate} from '@shopify/dates';

const date = new Date('2020-02-18Z14:00');
const locales = 'en';
const options = {
timeZone: 'America/New_York',
hour: 'numeric',
};

const newDate = formatDate(date, locales, options); // 9 AM
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new date is just 9 AM?

Copy link
Contributor Author

@helloneele helloneele Feb 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's based on the options you pass it apparently. By doing hour: 'numeric' it'll just return the hour. If you don't specify hour it'll give you the date like this 2/18/2020

```

### `getDateTimeParts`

Takes in a date object and an optional time zone string parameter. Returns an object with functions to get the year, month, day, weekday, hour, minute and second of the provided date.
Expand Down
2 changes: 1 addition & 1 deletion packages/dates/src/get-date-time-parts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {memoize} from '@shopify/decorators';

import {formatDate} from './utilities/formatDate';
import {formatDate} from './utilities';
import {sanitiseDateString} from './sanitise-date-string';

const TWO_DIGIT_REGEX = /(\d{2})/;
Expand Down
1 change: 1 addition & 0 deletions packages/dates/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from './parse-date-string-parts';
export * from './sanitise-date-string';
export * from './unapply-time-zone-offset';
export * from './map-deprecated-timezones';
export * from './utilities';
1 change: 1 addition & 0 deletions packages/dates/src/utilities/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {formatDate} from './formatDate';
6 changes: 5 additions & 1 deletion packages/dates/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@
"./src/**/*.tsx"
],
"exclude": ["**/*.test.ts", "**/*.test.tsx"],
"references": [{"path": "../address"}, {"path": "../function-enhancers"}, {"path": "../decorators"}]
"references": [
{"path": "../address"},
{"path": "../function-enhancers"},
{"path": "../decorators"}
]
}