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

Commit

Permalink
Export formatDate function
Browse files Browse the repository at this point in the history
  • Loading branch information
Neele Barthel committed Feb 19, 2020
1 parent ec40568 commit 4bd303c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
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
```

### `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"}
]
}

0 comments on commit 4bd303c

Please sign in to comment.