@contentful/f36-datetime 4.12.0 → 4.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.15.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies []:
8
+ - @contentful/f36-core@4.15.0
9
+
10
+ ## 4.14.0
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies []:
15
+ - @contentful/f36-core@4.14.0
16
+
17
+ ## 4.13.0
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies []:
22
+ - @contentful/f36-core@4.13.0
23
+
3
24
  ## 4.12.0
4
25
 
5
26
  ### Minor Changes
package/dist/main.js CHANGED
@@ -19,70 +19,70 @@ $parcel$export(module.exports, "formatRelativeDateTime", () => $4e7e5146bc048e19
19
19
 
20
20
 
21
21
 
22
- ($parcel$interopDefault($iSxHR$dayjs)).extend(($parcel$interopDefault($iSxHR$dayjspluginutc)));
23
- function $fe3d2807f48471b7$export$de4eb09f10f9c95e(date, format = 'full') {
22
+ (0, ($parcel$interopDefault($iSxHR$dayjs))).extend((0, ($parcel$interopDefault($iSxHR$dayjspluginutc))));
23
+ function $fe3d2807f48471b7$export$de4eb09f10f9c95e(date, format = "full") {
24
24
  let template;
25
25
  switch(format){
26
- case 'day':
27
- template = 'DD MMM YYYY'; // 17 Aug 2021
26
+ case "day":
27
+ template = "DD MMM YYYY"; // 17 Aug 2021
28
28
  break;
29
- case 'weekday':
30
- template = 'ddd, DD MMM'; // Tue, 17 Aug
29
+ case "weekday":
30
+ template = "ddd, DD MMM"; // Tue, 17 Aug
31
31
  break;
32
- case 'time':
33
- template = 'h:mm A'; // 3:45 PM
32
+ case "time":
33
+ template = "h:mm A"; // 3:45 PM
34
34
  break;
35
- case 'fullWithSeconds':
36
- template = 'ddd, DD MMM YYYY [at] h:mm:ss A'; // Tue, 17 Aug 2021 at 3:45:67 PM
35
+ case "fullWithSeconds":
36
+ template = "ddd, DD MMM YYYY [at] h:mm:ss A"; // Tue, 17 Aug 2021 at 3:45:67 PM
37
37
  break;
38
38
  default:
39
- template = 'ddd, DD MMM YYYY [at] h:mm A';
39
+ template = "ddd, DD MMM YYYY [at] h:mm A";
40
40
  }
41
- return ($parcel$interopDefault($iSxHR$dayjs))(date).format(template);
41
+ return (0, ($parcel$interopDefault($iSxHR$dayjs)))(date).format(template);
42
42
  }
43
- function $fe3d2807f48471b7$export$5fb913e47d486079(date, format = 'full') {
43
+ function $fe3d2807f48471b7$export$5fb913e47d486079(date, format = "full") {
44
44
  let template;
45
45
  switch(format){
46
- case 'day':
47
- template = 'YYYY-MM-DD'; // 2019-08-24
46
+ case "day":
47
+ template = "YYYY-MM-DD"; // 2019-08-24
48
48
  break;
49
- case 'weekday':
50
- template = 'MM-DD'; // 08-24
49
+ case "weekday":
50
+ template = "MM-DD"; // 08-24
51
51
  break;
52
- case 'time':
53
- template = 'HH:mm:ss.SSS'; // 15:44:07.000
52
+ case "time":
53
+ template = "HH:mm:ss.SSS"; // 15:44:07.000
54
54
  break;
55
55
  default:
56
- template = 'YYYY-MM-DDTHH:mm:ss.SSS[Z]';
56
+ template = "YYYY-MM-DDTHH:mm:ss.SSS[Z]";
57
57
  }
58
- return ($parcel$interopDefault($iSxHR$dayjs))(date).utc().format(template);
58
+ return (0, ($parcel$interopDefault($iSxHR$dayjs)))(date).utc().format(template);
59
59
  }
60
60
  const $fe3d2807f48471b7$export$3ae94a2503e890a1 = (date)=>{
61
- return $fe3d2807f48471b7$export$de4eb09f10f9c95e(date, 'day');
61
+ return $fe3d2807f48471b7$export$de4eb09f10f9c95e(date, "day");
62
62
  };
63
63
  const $fe3d2807f48471b7$export$3203edd9e5edd663 = (date)=>{
64
- return $fe3d2807f48471b7$export$de4eb09f10f9c95e(date, 'time');
64
+ return $fe3d2807f48471b7$export$de4eb09f10f9c95e(date, "time");
65
65
  };
66
66
  const $fe3d2807f48471b7$export$b89623867a65b725 = (date)=>{
67
- return $fe3d2807f48471b7$export$de4eb09f10f9c95e(date, 'weekday');
67
+ return $fe3d2807f48471b7$export$de4eb09f10f9c95e(date, "weekday");
68
68
  };
69
69
 
70
70
 
71
71
 
72
72
 
73
73
 
74
- ($parcel$interopDefault($iSxHR$dayjs)).extend(($parcel$interopDefault($iSxHR$dayjspluginutc)));
75
- ($parcel$interopDefault($iSxHR$dayjs)).extend(($parcel$interopDefault($iSxHR$dayjspluginrelativeTime)));
76
- ($parcel$interopDefault($iSxHR$dayjs)).extend(($parcel$interopDefault($iSxHR$dayjsplugincalendar)));
74
+ (0, ($parcel$interopDefault($iSxHR$dayjs))).extend((0, ($parcel$interopDefault($iSxHR$dayjspluginutc))));
75
+ (0, ($parcel$interopDefault($iSxHR$dayjs))).extend((0, ($parcel$interopDefault($iSxHR$dayjspluginrelativeTime))));
76
+ (0, ($parcel$interopDefault($iSxHR$dayjs))).extend((0, ($parcel$interopDefault($iSxHR$dayjsplugincalendar))));
77
77
  function $4e7e5146bc048e19$export$68534c3ecebfa124(date, baseDate = new Date()) {
78
- return ($parcel$interopDefault($iSxHR$dayjs))(date).from(baseDate);
78
+ return (0, ($parcel$interopDefault($iSxHR$dayjs)))(date).from(baseDate);
79
79
  }
80
80
  function $4e7e5146bc048e19$export$aa1a2def90bfd930(date, baseDate = new Date()) {
81
- const isToday = ($parcel$interopDefault($iSxHR$dayjs))(date).isSame(baseDate, 'day');
81
+ const isToday = (0, ($parcel$interopDefault($iSxHR$dayjs)))(date).isSame(baseDate, "day");
82
82
  if (!isToday) // if the date is not today, we display it with "Yesterday", "Tomorrow", etc.
83
83
  // and if the date is not in the current week then it will display "17 Aug 2021"
84
- return ($parcel$interopDefault($iSxHR$dayjs))(date).calendar(baseDate, {
85
- sameElse: 'DD MMM YYYY'
84
+ return (0, ($parcel$interopDefault($iSxHR$dayjs)))(date).calendar(baseDate, {
85
+ sameElse: "DD MMM YYYY"
86
86
  });
87
87
  // returns "... ago"
88
88
  return $4e7e5146bc048e19$export$68534c3ecebfa124(date, baseDate);
@@ -90,16 +90,16 @@ function $4e7e5146bc048e19$export$aa1a2def90bfd930(date, baseDate = new Date())
90
90
 
91
91
 
92
92
 
93
- const $8c9ef2783da7ec5f$var$_DateTime = ({ date: date , format: format = 'full' , testId: testId = 'cf-ui-date-time' , ...otherProps }, ref)=>{
94
- const machineReadableDate = $fe3d2807f48471b7$export$5fb913e47d486079(date);
95
- return /*#__PURE__*/ ($parcel$interopDefault($iSxHR$react)).createElement("time", {
93
+ const $8c9ef2783da7ec5f$var$_DateTime = ({ date: date , format: format = "full" , testId: testId = "cf-ui-date-time" , ...otherProps }, ref)=>{
94
+ const machineReadableDate = (0, $fe3d2807f48471b7$export$5fb913e47d486079)(date);
95
+ return /*#__PURE__*/ (0, ($parcel$interopDefault($iSxHR$react))).createElement("time", {
96
96
  dateTime: machineReadableDate,
97
97
  "data-test-id": testId,
98
98
  ...otherProps,
99
99
  ref: ref
100
- }, $fe3d2807f48471b7$export$de4eb09f10f9c95e(date, format));
100
+ }, (0, $fe3d2807f48471b7$export$de4eb09f10f9c95e)(date, format));
101
101
  };
102
- const $8c9ef2783da7ec5f$export$82f9ebd9adeba146 = /*#__PURE__*/ ($parcel$interopDefault($iSxHR$react)).forwardRef($8c9ef2783da7ec5f$var$_DateTime);
102
+ const $8c9ef2783da7ec5f$export$82f9ebd9adeba146 = /*#__PURE__*/ (0, ($parcel$interopDefault($iSxHR$react))).forwardRef($8c9ef2783da7ec5f$var$_DateTime);
103
103
 
104
104
 
105
105
 
@@ -108,31 +108,31 @@ const $8c9ef2783da7ec5f$export$82f9ebd9adeba146 = /*#__PURE__*/ ($parcel$interop
108
108
 
109
109
 
110
110
 
111
- ($parcel$interopDefault($iSxHR$dayjs)).extend(($parcel$interopDefault($iSxHR$dayjspluginutc)));
112
- ($parcel$interopDefault($iSxHR$dayjs)).extend(($parcel$interopDefault($iSxHR$dayjspluginrelativeTime)));
113
- ($parcel$interopDefault($iSxHR$dayjs)).extend(($parcel$interopDefault($iSxHR$dayjsplugincalendar)));
114
- const $de66f20f0f273947$var$_RelativeDateTime = ({ date: date , baseDate: baseDate , isRelativeToCurrentWeek: isRelativeToCurrentWeek = false , testId: testId = 'cf-ui-relative-date-time' , ...otherProps }, ref)=>{
111
+ (0, ($parcel$interopDefault($iSxHR$dayjs))).extend((0, ($parcel$interopDefault($iSxHR$dayjspluginutc))));
112
+ (0, ($parcel$interopDefault($iSxHR$dayjs))).extend((0, ($parcel$interopDefault($iSxHR$dayjspluginrelativeTime))));
113
+ (0, ($parcel$interopDefault($iSxHR$dayjs))).extend((0, ($parcel$interopDefault($iSxHR$dayjsplugincalendar))));
114
+ const $de66f20f0f273947$var$_RelativeDateTime = ({ date: date , baseDate: baseDate , isRelativeToCurrentWeek: isRelativeToCurrentWeek = false , testId: testId = "cf-ui-relative-date-time" , ...otherProps }, ref)=>{
115
115
  const now = new Date();
116
116
  const referenceDate = baseDate !== null && baseDate !== void 0 ? baseDate : now;
117
- const dayjsDate = ($parcel$interopDefault($iSxHR$dayjs))(date);
118
- const machineReadableDate = $fe3d2807f48471b7$export$5fb913e47d486079(date);
117
+ const dayjsDate = (0, ($parcel$interopDefault($iSxHR$dayjs)))(date);
118
+ const machineReadableDate = (0, $fe3d2807f48471b7$export$5fb913e47d486079)(date);
119
119
  let relativeDate;
120
- if (isRelativeToCurrentWeek && !dayjsDate.isSame(referenceDate, 'day')) /**
120
+ if (isRelativeToCurrentWeek && !dayjsDate.isSame(referenceDate, "day")) /**
121
121
  * if isRelativeToCurrentWeek is true and the date is not today, we display the date with Yesterday, Tomorrow, etc
122
122
  * or, if the date is not in the current week, it displays "17 Aug 2021"
123
123
  *
124
124
  * check formatRelativeToCurrentWeekDateTime for more details
125
- */ relativeDate = $4e7e5146bc048e19$export$aa1a2def90bfd930(date, referenceDate);
125
+ */ relativeDate = (0, $4e7e5146bc048e19$export$aa1a2def90bfd930)(date, referenceDate);
126
126
  else // otherwise we display it with "... ago" or "in ..." notation
127
- relativeDate = $4e7e5146bc048e19$export$68534c3ecebfa124(date, referenceDate);
128
- return /*#__PURE__*/ ($parcel$interopDefault($iSxHR$react)).createElement("time", {
127
+ relativeDate = (0, $4e7e5146bc048e19$export$68534c3ecebfa124)(date, referenceDate);
128
+ return /*#__PURE__*/ (0, ($parcel$interopDefault($iSxHR$react))).createElement("time", {
129
129
  dateTime: machineReadableDate,
130
130
  "data-test-id": testId,
131
131
  ...otherProps,
132
132
  ref: ref
133
133
  }, relativeDate);
134
134
  };
135
- const $de66f20f0f273947$export$6de14fd95adb1c8a = /*#__PURE__*/ ($parcel$interopDefault($iSxHR$react)).forwardRef($de66f20f0f273947$var$_RelativeDateTime);
135
+ const $de66f20f0f273947$export$6de14fd95adb1c8a = /*#__PURE__*/ (0, ($parcel$interopDefault($iSxHR$react))).forwardRef($de66f20f0f273947$var$_RelativeDateTime);
136
136
 
137
137
 
138
138
 
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;ACAA;AEAA;;AAEA4B,sCAAK,CAACE,MAAN,CAAaD,+CAAb,CAAAD,CAAAA;AAmBO,SAASxB,yCAAT,CACLU,IADK,EAELC,MAAkB,GAAG,MAFhB,EAGG;IACR,IAAIgB,QAAQ,AAAZ,AAAA;IAEA,OAAQhB,MAAR;QACE,KAAK,KAAL;YACEgB,QAAQ,GAAG,aAAX,CADF,CAC4B,cAA1BA;YACA,MAAA;QACF,KAAK,SAAL;YACEA,QAAQ,GAAG,aAAX,CADF,CAC4B,cAA1BA;YACA,MAAA;QACF,KAAK,MAAL;YACEA,QAAQ,GAAG,QAAX,CADF,CACuB,UAArBA;YACA,MAAA;QACF,KAAK,iBAAL;YACEA,QAAQ,GAAG,iCAAX,CADF,CACgD,iCAA9CA;YACA,MAAA;QACF;YACEA,QAAQ,GAAG,8BAAX,CAAAA;KAdJ;IAiBA,OAAOH,sCAAK,CAACd,IAAD,CAAL,CAAYC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BAAuB,GAAG,KAH5B,WAIE1B,MAAM,GAAG,0BAJX,GAKE,GAAGC,UAAH,EANsB,EAQxBC,GARwB,GASrB;IACH,MAAM0B,GAAG,GAAG,IAAIT,IAAJ,EAAZ,AAAA;IACA,MAAMU,aAAa,GAAGX,QAAQ,aAARA,QAAQ,cAARA,QAAQ,GAAIU,GAAlC,AAAA;IACA,MAAME,SAAS,GAAGnB,sCAAK,CAACd,IAAD,CAAvB,AAAA;IACA,MAAMQ,mBAAmB,GAAGjB,yCAA6B,CAACS,IAAD,CAAzD,AAAA;IAEA,IAAIkC,YAAY,AAAhB,AAAA;IAEA,IAAIL,uBAAuB,IAAI,CAACI,SAAS,CAACR,MAAV,CAAiBO,aAAjB,EAAgC,KAAhC,CAAhC,EACE;;;;;OAKJ,CACIE,YAAY,GAAGrB,yCAAmC,CAACb,IAAD,EAAOgC,aAAP,CAAlD,CAAAE;SAEA,8DAAA;IACAA,YAAY,GAAG1C,yCAAsB,CAACQ,IAAD,EAAOgC,aAAP,CAArC,CAAAE;IAGF,qBACE,qDAAC,MAAD;QACE,QAAA,EAAU1B,mBAAD;QACT,cAAA,EAAcL,MAAD;QACb,GAAIC,UAAJ;QACA,GAAA,EAAKC,GAAD;OAEH6B,YAAD,CAPJ,CAQF;CAtCA,AAwCC;AAMM,MAAM9C,yCAAgB,iBAAGK,sCAAK,CAACgB,UAAN,CAAiBqB,uCAAjB,CAAzB,AAAP;","sources":["packages/components/datetime/src/index.ts","packages/components/datetime/src/DateTime/DateTime.tsx","packages/components/datetime/src/utils/index.ts","packages/components/datetime/src/utils/formatDateTimeUtils.ts","packages/components/datetime/src/utils/relativeDateTimeUtils.ts","packages/components/datetime/src/RelativeDateTime/RelativeDateTime.tsx"],"sourcesContent":["export { DateTime } from './DateTime/DateTime';\nexport type { DateTimeProps } from './DateTime/DateTime';\nexport { RelativeDateTime } from './RelativeDateTime/RelativeDateTime';\nexport type { RelativeDateTimeProps } from './RelativeDateTime/RelativeDateTime';\nexport {\n formatDateAndTime,\n formatMachineReadableDateTime,\n formatRelativeDateTime,\n} from './utils';\n","import React from 'react';\nimport type {\n CommonProps,\n PropsWithHTMLElement,\n ExpandProps,\n} from '@contentful/f36-core';\n\nimport type { DateType, DateFormat } from '../types';\nimport { formatDateAndTime, formatMachineReadableDateTime } from '../utils';\n\ninterface DateTimeOwnProps extends CommonProps {\n /**\n * The date that will be displayed. It accepts a JS Date, an ISO8601 Timestamp string, or Unix Epoch Milliseconds number\n */\n date: DateType;\n /**\n * The format in which the date will be presented\n *\n * @default full\n **/\n format?: DateFormat;\n}\n\nexport type DateTimeProps = PropsWithHTMLElement<DateTimeOwnProps, 'time'>;\n\nconst _DateTime = (\n {\n date,\n format = 'full',\n testId = 'cf-ui-date-time',\n ...otherProps\n }: ExpandProps<DateTimeProps>,\n ref: React.Ref<HTMLTimeElement>,\n) => {\n const machineReadableDate = formatMachineReadableDateTime(date);\n\n return (\n <time\n dateTime={machineReadableDate}\n data-test-id={testId}\n {...otherProps}\n ref={ref}\n >\n {formatDateAndTime(date, format)}\n </time>\n );\n};\n\n/**\n * The DateTime component will format a date to a human friendly format and wrap it in a `<time>` tag\n */\nexport const DateTime = React.forwardRef(_DateTime);\n","export {\n formatDateAndTime,\n formatMachineReadableDateTime,\n formatDate,\n formatTime,\n formatWeekdayDate,\n} from './formatDateTimeUtils';\n\nexport {\n formatRelativeDateTime,\n formatRelativeToCurrentWeekDateTime,\n} from './relativeDateTimeUtils';\n","import dayjs from 'dayjs';\nimport utcPlugin from 'dayjs/plugin/utc';\ndayjs.extend(utcPlugin);\n\nimport type { DateType, DateFormat } from '../types';\n\n/**\n * A funtion that will return a formatted date string. The format will dependend on the option\n * passed in the second argument.\n * By default, it will return a string with Forma 36’s \"full\" format (e.g. Tue, 17 Aug 2021 at 3:45 PM)\n *\n * @param {DateType} date - the date to be formatted\n * @param {DateFormat} format - the desired format (\"full\", \"day\", \"weekday\", or \"time\")\n * @returns a formatted date\n *\n * @example\n * formatDateAndTime('2021-08-17T15:45:00') // returns \"Tue, 17 Aug 2021 at 3:45 PM\"\n *\n * @example\n * formatDateAndTime('2021-08-17T15:45:00', 'day') // returns \"17 Aug 2021\"\n */\nexport function formatDateAndTime(\n date: DateType,\n format: DateFormat = 'full',\n): string {\n let template: string;\n\n switch (format) {\n case 'day':\n template = 'DD MMM YYYY'; // 17 Aug 2021\n break;\n case 'weekday':\n template = 'ddd, DD MMM'; // Tue, 17 Aug\n break;\n case 'time':\n template = 'h:mm A'; // 3:45 PM\n break;\n case 'fullWithSeconds':\n template = 'ddd, DD MMM YYYY [at] h:mm:ss A'; // Tue, 17 Aug 2021 at 3:45:67 PM\n break;\n default:\n template = 'ddd, DD MMM YYYY [at] h:mm A'; // Tue, 17 Aug 2021 at 3:45 PM\n }\n\n return dayjs(date).format(template);\n}\n\n/**\n * A funtion that will return a machine-readable date string that should be passed to the `datetime` attribute of a `<time>` tag\n * By default, it will return a string with \"YYYY-MM-DDTHH:mm:ss.SSS[Z]\" format\n *\n * @param {DateType} date - the date to be formatted\n * @param {DateFormat} format - the desired format (\"full\", \"day\", \"weekday\", or \"time\")\n * @returns a formatted date\n *\n * @example\n * formatMachineReadableDateTime(date) // returns 2019-08-13T10:00:00.000Z\n *\n * @example\n * formatMachineReadableDateTime(date, 'day') // returns 2019-08-13\n */\nexport function formatMachineReadableDateTime(\n date: DateType,\n format: DateFormat = 'full',\n): string {\n let template: string;\n\n switch (format) {\n case 'day':\n template = 'YYYY-MM-DD'; // 2019-08-24\n break;\n case 'weekday':\n template = 'MM-DD'; // 08-24\n break;\n case 'time':\n template = 'HH:mm:ss.SSS'; // 15:44:07.000\n break;\n default:\n template = 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'; // 2019-08-24T15:44:07.000Z\n }\n\n return dayjs(date).utc().format(template);\n}\n\n/**\n * @example\n * > formatDate(date)\n * 13 Aug 2019\n */\nexport const formatDate = (date: DateType): string => {\n return formatDateAndTime(date, 'day');\n};\n\n/**\n * @example\n * > formatTime(date)\n * 8:00 AM\n */\nexport const formatTime = (date: DateType): string => {\n return formatDateAndTime(date, 'time');\n};\n\n/**\n * @example\n * > formatWeekdayDate(date)\n * Mon, 12 Aug\n */\nexport const formatWeekdayDate = (date: DateType): string => {\n return formatDateAndTime(date, 'weekday');\n};\n","import dayjs from 'dayjs';\nimport utcPlugin from 'dayjs/plugin/utc';\nimport relativeTime from 'dayjs/plugin/relativeTime';\nimport calendarPlugin from 'dayjs/plugin/calendar';\ndayjs.extend(utcPlugin);\ndayjs.extend(relativeTime);\ndayjs.extend(calendarPlugin);\n\nimport type { DateType } from '../types';\n\n/**\n * A function that will return a string with how far a given date is in the past or future,\n * using a baseDate as reference. If the baseDate is not passed, the function will use today as reference.\n *\n * @param {DateType} date - the date to be formatted\n * @param {DateFormat} baseDate - the date that should be used as a reference (default is \"today\")\n * @returns a relative date\n *\n * @example\n * // Considering today as 18.08.2021\n * formatRelativeDateTime('2021-08-17T15:45:00') // returns \"a day ago\"\n *\n * @example\n * formatRelativeDateTime('2021-08-17T15:45:00', '2021-08-16') // returns \"in a day\"\n */\nexport function formatRelativeDateTime(\n date: DateType,\n baseDate: DateType = new Date(),\n) {\n return dayjs(date).from(baseDate);\n}\n\n/**\n * A function that formats a date relative to Today or to the `baseDate` if passed.\n * If the date is not today, it will return a string with \"Yesterday ...\", \"Tomorrow ...\", etc\n * If the date is not in the current week, it return a string with \"DD MMM YYYY\" format\n * If the date is today, it will return a string with \"... ago\" or \"in ...\"\n *\n * @param {DateType} date - the date to be formatted\n * @param {DateFormat} baseDate - the date that should be used as a reference (default is \"today\")\n * @returns a relative date\n *\n * @example\n * // Considering today as 18.08.2021\n * formatRelativeToCurrentWeekDateTime('2021-08-17T15:45:00') // returns \"Yesterday at 3:45 PM\"\n *\n * @example\n * formatRelativeToCurrentWeekDateTime('2021-08-17T15:45:00', '2021-08-16') // returns \"Tomorrow at 3:45 PM\"\n */\nexport function formatRelativeToCurrentWeekDateTime(\n date: DateType,\n baseDate: DateType = new Date(),\n) {\n const isToday = dayjs(date).isSame(baseDate, 'day');\n\n if (!isToday) {\n // if the date is not today, we display it with \"Yesterday\", \"Tomorrow\", etc.\n // and if the date is not in the current week then it will display \"17 Aug 2021\"\n return dayjs(date).calendar(baseDate, {\n sameElse: 'DD MMM YYYY',\n });\n }\n\n // returns \"... ago\"\n return formatRelativeDateTime(date, baseDate);\n}\n","import React from 'react';\nimport type {\n CommonProps,\n PropsWithHTMLElement,\n ExpandProps,\n} from '@contentful/f36-core';\n\nimport dayjs from 'dayjs';\nimport utcPlugin from 'dayjs/plugin/utc';\nimport relativeTime from 'dayjs/plugin/relativeTime';\nimport calendarPlugin from 'dayjs/plugin/calendar';\ndayjs.extend(utcPlugin);\ndayjs.extend(relativeTime);\ndayjs.extend(calendarPlugin);\n\nimport type { DateType } from '../types';\nimport {\n formatMachineReadableDateTime,\n formatRelativeDateTime,\n formatRelativeToCurrentWeekDateTime,\n} from '../utils';\n\ninterface RelativeDateTimeInternalProps extends CommonProps {\n /**\n * The date that will be displayed. It accepts a JS Date, an ISO8601 Timestamp string, or Unix Epoch Milliseconds number\n */\n date: DateType;\n /**\n * If a value is passed to baseDate, then the component will compare both dates and return the time between them.\n * If no value is passed then the date will be compared to \"now\"\n *\n * @default \"Now\"\n */\n baseDate?: DateType;\n /**\n * Sets the date to be relative only if it is in the current week\n * @default false\n */\n isRelativeToCurrentWeek?: boolean;\n}\n\nexport type RelativeDateTimeProps = PropsWithHTMLElement<\n RelativeDateTimeInternalProps,\n 'time'\n>;\n\nconst _RelativeDateTime = (\n {\n date,\n baseDate,\n isRelativeToCurrentWeek = false,\n testId = 'cf-ui-relative-date-time',\n ...otherProps\n }: ExpandProps<RelativeDateTimeProps>,\n ref: React.Ref<HTMLTimeElement>,\n) => {\n const now = new Date();\n const referenceDate = baseDate ?? now;\n const dayjsDate = dayjs(date);\n const machineReadableDate = formatMachineReadableDateTime(date);\n\n let relativeDate: string;\n\n if (isRelativeToCurrentWeek && !dayjsDate.isSame(referenceDate, 'day')) {\n /**\n * if isRelativeToCurrentWeek is true and the date is not today, we display the date with Yesterday, Tomorrow, etc\n * or, if the date is not in the current week, it displays \"17 Aug 2021\"\n *\n * check formatRelativeToCurrentWeekDateTime for more details\n */\n relativeDate = formatRelativeToCurrentWeekDateTime(date, referenceDate);\n } else {\n // otherwise we display it with \"... ago\" or \"in ...\" notation\n relativeDate = formatRelativeDateTime(date, referenceDate);\n }\n\n return (\n <time\n dateTime={machineReadableDate}\n data-test-id={testId}\n {...otherProps}\n ref={ref}\n >\n {relativeDate}\n </time>\n );\n};\n\n/**\n * The RelativeDateTime will show a `date` relative to \"now\" or to the `baseDate`\n * (e.g. in a day, in one month, one month ago, etc).\n */\nexport const RelativeDateTime = React.forwardRef(_RelativeDateTime);\n"],"names":["DateTime","DateTimeProps","RelativeDateTime","RelativeDateTimeProps","formatDateAndTime","formatMachineReadableDateTime","formatRelativeDateTime","React","CommonProps","PropsWithHTMLElement","ExpandProps","DateType","DateFormat","DateTimeOwnProps","date","format","_DateTime","testId","otherProps","ref","Ref","HTMLTimeElement","machineReadableDate","forwardRef","formatDate","formatTime","formatWeekdayDate","formatRelativeToCurrentWeekDateTime","dayjs","utcPlugin","extend","template","utc","relativeTime","calendarPlugin","baseDate","Date","from","isToday","isSame","calendar","sameElse","RelativeDateTimeInternalProps","isRelativeToCurrentWeek","_RelativeDateTime","now","referenceDate","dayjsDate","relativeDate"],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;ACAA;AEAA;;AAEA4B,CAAAA,GAAAA,sCAAK,CAAA,CAACE,MAAN,CAAaD,CAAAA,GAAAA,+CAAb,CAAA,CAAAD,CAAAA;AAmBO,SAASxB,yCAAT,CACLU,IADK,EAELC,MAAkB,GAAG,MAFhB,EAGG;IACR,IAAIgB,QAAQ,AAAZ,AAAA;IAEA,OAAQhB,MAAR;QACE,KAAK,KAAL;YACEgB,QAAQ,GAAG,aAAX,CADF,CAC4B,cAA1BA;YACA,MAA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AY,GAAGrB,CAAAA,GAAAA,yCAAmC,CAAA,CAACb,IAAD,EAAOgC,aAAP,CAAlD,CAAAE;SAEA,8DAAA;IACAA,YAAY,GAAG1C,CAAAA,GAAAA,yCAAsB,CAAA,CAACQ,IAAD,EAAOgC,aAAP,CAArC,CAAAE;IAGF,qBACE,0DAAC,MAAD;QACE,QAAA,EAAU1B,mBAAD;QACT,cAAA,EAAcL,MAAD;QACb,GAAIC,UAAJ;QACA,GAAA,EAAKC,GAAD;OAEH6B,YAAD,CAPJ,CAQF;CAtCA,AAwCC;AAMM,MAAM9C,yCAAgB,iBAAGK,CAAAA,GAAAA,sCAAK,CAAA,CAACgB,UAAN,CAAiBqB,uCAAjB,CAAzB,AAAP;","sources":["packages/components/datetime/src/index.ts","packages/components/datetime/src/DateTime/DateTime.tsx","packages/components/datetime/src/utils/index.ts","packages/components/datetime/src/utils/formatDateTimeUtils.ts","packages/components/datetime/src/utils/relativeDateTimeUtils.ts","packages/components/datetime/src/RelativeDateTime/RelativeDateTime.tsx"],"sourcesContent":["export { DateTime } from './DateTime/DateTime';\nexport type { DateTimeProps } from './DateTime/DateTime';\nexport { RelativeDateTime } from './RelativeDateTime/RelativeDateTime';\nexport type { RelativeDateTimeProps } from './RelativeDateTime/RelativeDateTime';\nexport {\n formatDateAndTime,\n formatMachineReadableDateTime,\n formatRelativeDateTime,\n} from './utils';\n","import React from 'react';\nimport type {\n CommonProps,\n PropsWithHTMLElement,\n ExpandProps,\n} from '@contentful/f36-core';\n\nimport type { DateType, DateFormat } from '../types';\nimport { formatDateAndTime, formatMachineReadableDateTime } from '../utils';\n\ninterface DateTimeOwnProps extends CommonProps {\n /**\n * The date that will be displayed. It accepts a JS Date, an ISO8601 Timestamp string, or Unix Epoch Milliseconds number\n */\n date: DateType;\n /**\n * The format in which the date will be presented\n *\n * @default full\n **/\n format?: DateFormat;\n}\n\nexport type DateTimeProps = PropsWithHTMLElement<DateTimeOwnProps, 'time'>;\n\nconst _DateTime = (\n {\n date,\n format = 'full',\n testId = 'cf-ui-date-time',\n ...otherProps\n }: ExpandProps<DateTimeProps>,\n ref: React.Ref<HTMLTimeElement>,\n) => {\n const machineReadableDate = formatMachineReadableDateTime(date);\n\n return (\n <time\n dateTime={machineReadableDate}\n data-test-id={testId}\n {...otherProps}\n ref={ref}\n >\n {formatDateAndTime(date, format)}\n </time>\n );\n};\n\n/**\n * The DateTime component will format a date to a human friendly format and wrap it in a `<time>` tag\n */\nexport const DateTime = React.forwardRef(_DateTime);\n","export {\n formatDateAndTime,\n formatMachineReadableDateTime,\n formatDate,\n formatTime,\n formatWeekdayDate,\n} from './formatDateTimeUtils';\n\nexport {\n formatRelativeDateTime,\n formatRelativeToCurrentWeekDateTime,\n} from './relativeDateTimeUtils';\n","import dayjs from 'dayjs';\nimport utcPlugin from 'dayjs/plugin/utc';\ndayjs.extend(utcPlugin);\n\nimport type { DateType, DateFormat } from '../types';\n\n/**\n * A funtion that will return a formatted date string. The format will dependend on the option\n * passed in the second argument.\n * By default, it will return a string with Forma 36’s \"full\" format (e.g. Tue, 17 Aug 2021 at 3:45 PM)\n *\n * @param {DateType} date - the date to be formatted\n * @param {DateFormat} format - the desired format (\"full\", \"day\", \"weekday\", or \"time\")\n * @returns a formatted date\n *\n * @example\n * formatDateAndTime('2021-08-17T15:45:00') // returns \"Tue, 17 Aug 2021 at 3:45 PM\"\n *\n * @example\n * formatDateAndTime('2021-08-17T15:45:00', 'day') // returns \"17 Aug 2021\"\n */\nexport function formatDateAndTime(\n date: DateType,\n format: DateFormat = 'full',\n): string {\n let template: string;\n\n switch (format) {\n case 'day':\n template = 'DD MMM YYYY'; // 17 Aug 2021\n break;\n case 'weekday':\n template = 'ddd, DD MMM'; // Tue, 17 Aug\n break;\n case 'time':\n template = 'h:mm A'; // 3:45 PM\n break;\n case 'fullWithSeconds':\n template = 'ddd, DD MMM YYYY [at] h:mm:ss A'; // Tue, 17 Aug 2021 at 3:45:67 PM\n break;\n default:\n template = 'ddd, DD MMM YYYY [at] h:mm A'; // Tue, 17 Aug 2021 at 3:45 PM\n }\n\n return dayjs(date).format(template);\n}\n\n/**\n * A funtion that will return a machine-readable date string that should be passed to the `datetime` attribute of a `<time>` tag\n * By default, it will return a string with \"YYYY-MM-DDTHH:mm:ss.SSS[Z]\" format\n *\n * @param {DateType} date - the date to be formatted\n * @param {DateFormat} format - the desired format (\"full\", \"day\", \"weekday\", or \"time\")\n * @returns a formatted date\n *\n * @example\n * formatMachineReadableDateTime(date) // returns 2019-08-13T10:00:00.000Z\n *\n * @example\n * formatMachineReadableDateTime(date, 'day') // returns 2019-08-13\n */\nexport function formatMachineReadableDateTime(\n date: DateType,\n format: DateFormat = 'full',\n): string {\n let template: string;\n\n switch (format) {\n case 'day':\n template = 'YYYY-MM-DD'; // 2019-08-24\n break;\n case 'weekday':\n template = 'MM-DD'; // 08-24\n break;\n case 'time':\n template = 'HH:mm:ss.SSS'; // 15:44:07.000\n break;\n default:\n template = 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'; // 2019-08-24T15:44:07.000Z\n }\n\n return dayjs(date).utc().format(template);\n}\n\n/**\n * @example\n * > formatDate(date)\n * 13 Aug 2019\n */\nexport const formatDate = (date: DateType): string => {\n return formatDateAndTime(date, 'day');\n};\n\n/**\n * @example\n * > formatTime(date)\n * 8:00 AM\n */\nexport const formatTime = (date: DateType): string => {\n return formatDateAndTime(date, 'time');\n};\n\n/**\n * @example\n * > formatWeekdayDate(date)\n * Mon, 12 Aug\n */\nexport const formatWeekdayDate = (date: DateType): string => {\n return formatDateAndTime(date, 'weekday');\n};\n","import dayjs from 'dayjs';\nimport utcPlugin from 'dayjs/plugin/utc';\nimport relativeTime from 'dayjs/plugin/relativeTime';\nimport calendarPlugin from 'dayjs/plugin/calendar';\ndayjs.extend(utcPlugin);\ndayjs.extend(relativeTime);\ndayjs.extend(calendarPlugin);\n\nimport type { DateType } from '../types';\n\n/**\n * A function that will return a string with how far a given date is in the past or future,\n * using a baseDate as reference. If the baseDate is not passed, the function will use today as reference.\n *\n * @param {DateType} date - the date to be formatted\n * @param {DateFormat} baseDate - the date that should be used as a reference (default is \"today\")\n * @returns a relative date\n *\n * @example\n * // Considering today as 18.08.2021\n * formatRelativeDateTime('2021-08-17T15:45:00') // returns \"a day ago\"\n *\n * @example\n * formatRelativeDateTime('2021-08-17T15:45:00', '2021-08-16') // returns \"in a day\"\n */\nexport function formatRelativeDateTime(\n date: DateType,\n baseDate: DateType = new Date(),\n) {\n return dayjs(date).from(baseDate);\n}\n\n/**\n * A function that formats a date relative to Today or to the `baseDate` if passed.\n * If the date is not today, it will return a string with \"Yesterday ...\", \"Tomorrow ...\", etc\n * If the date is not in the current week, it return a string with \"DD MMM YYYY\" format\n * If the date is today, it will return a string with \"... ago\" or \"in ...\"\n *\n * @param {DateType} date - the date to be formatted\n * @param {DateFormat} baseDate - the date that should be used as a reference (default is \"today\")\n * @returns a relative date\n *\n * @example\n * // Considering today as 18.08.2021\n * formatRelativeToCurrentWeekDateTime('2021-08-17T15:45:00') // returns \"Yesterday at 3:45 PM\"\n *\n * @example\n * formatRelativeToCurrentWeekDateTime('2021-08-17T15:45:00', '2021-08-16') // returns \"Tomorrow at 3:45 PM\"\n */\nexport function formatRelativeToCurrentWeekDateTime(\n date: DateType,\n baseDate: DateType = new Date(),\n) {\n const isToday = dayjs(date).isSame(baseDate, 'day');\n\n if (!isToday) {\n // if the date is not today, we display it with \"Yesterday\", \"Tomorrow\", etc.\n // and if the date is not in the current week then it will display \"17 Aug 2021\"\n return dayjs(date).calendar(baseDate, {\n sameElse: 'DD MMM YYYY',\n });\n }\n\n // returns \"... ago\"\n return formatRelativeDateTime(date, baseDate);\n}\n","import React from 'react';\nimport type {\n CommonProps,\n PropsWithHTMLElement,\n ExpandProps,\n} from '@contentful/f36-core';\n\nimport dayjs from 'dayjs';\nimport utcPlugin from 'dayjs/plugin/utc';\nimport relativeTime from 'dayjs/plugin/relativeTime';\nimport calendarPlugin from 'dayjs/plugin/calendar';\ndayjs.extend(utcPlugin);\ndayjs.extend(relativeTime);\ndayjs.extend(calendarPlugin);\n\nimport type { DateType } from '../types';\nimport {\n formatMachineReadableDateTime,\n formatRelativeDateTime,\n formatRelativeToCurrentWeekDateTime,\n} from '../utils';\n\ninterface RelativeDateTimeInternalProps extends CommonProps {\n /**\n * The date that will be displayed. It accepts a JS Date, an ISO8601 Timestamp string, or Unix Epoch Milliseconds number\n */\n date: DateType;\n /**\n * If a value is passed to baseDate, then the component will compare both dates and return the time between them.\n * If no value is passed then the date will be compared to \"now\"\n *\n * @default \"Now\"\n */\n baseDate?: DateType;\n /**\n * Sets the date to be relative only if it is in the current week\n * @default false\n */\n isRelativeToCurrentWeek?: boolean;\n}\n\nexport type RelativeDateTimeProps = PropsWithHTMLElement<\n RelativeDateTimeInternalProps,\n 'time'\n>;\n\nconst _RelativeDateTime = (\n {\n date,\n baseDate,\n isRelativeToCurrentWeek = false,\n testId = 'cf-ui-relative-date-time',\n ...otherProps\n }: ExpandProps<RelativeDateTimeProps>,\n ref: React.Ref<HTMLTimeElement>,\n) => {\n const now = new Date();\n const referenceDate = baseDate ?? now;\n const dayjsDate = dayjs(date);\n const machineReadableDate = formatMachineReadableDateTime(date);\n\n let relativeDate: string;\n\n if (isRelativeToCurrentWeek && !dayjsDate.isSame(referenceDate, 'day')) {\n /**\n * if isRelativeToCurrentWeek is true and the date is not today, we display the date with Yesterday, Tomorrow, etc\n * or, if the date is not in the current week, it displays \"17 Aug 2021\"\n *\n * check formatRelativeToCurrentWeekDateTime for more details\n */\n relativeDate = formatRelativeToCurrentWeekDateTime(date, referenceDate);\n } else {\n // otherwise we display it with \"... ago\" or \"in ...\" notation\n relativeDate = formatRelativeDateTime(date, referenceDate);\n }\n\n return (\n <time\n dateTime={machineReadableDate}\n data-test-id={testId}\n {...otherProps}\n ref={ref}\n >\n {relativeDate}\n </time>\n );\n};\n\n/**\n * The RelativeDateTime will show a `date` relative to \"now\" or to the `baseDate`\n * (e.g. in a day, in one month, one month ago, etc).\n */\nexport const RelativeDateTime = React.forwardRef(_RelativeDateTime);\n"],"names":["DateTime","DateTimeProps","RelativeDateTime","RelativeDateTimeProps","formatDateAndTime","formatMachineReadableDateTime","formatRelativeDateTime","React","CommonProps","PropsWithHTMLElement","ExpandProps","DateType","DateFormat","DateTimeOwnProps","date","format","_DateTime","testId","otherProps","ref","Ref","HTMLTimeElement","machineReadableDate","forwardRef","formatDate","formatTime","formatWeekdayDate","formatRelativeToCurrentWeekDateTime","dayjs","utcPlugin","extend","template","utc","relativeTime","calendarPlugin","baseDate","Date","from","isToday","isSame","calendar","sameElse","RelativeDateTimeInternalProps","isRelativeToCurrentWeek","_RelativeDateTime","now","referenceDate","dayjsDate","relativeDate"],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -7,70 +7,70 @@ import $fUYts$dayjsplugincalendar from "dayjs/plugin/calendar";
7
7
 
8
8
 
9
9
 
10
- $fUYts$dayjs.extend($fUYts$dayjspluginutc);
11
- function $ee655ad1301c8997$export$de4eb09f10f9c95e(date, format = 'full') {
10
+ (0, $fUYts$dayjs).extend((0, $fUYts$dayjspluginutc));
11
+ function $ee655ad1301c8997$export$de4eb09f10f9c95e(date, format = "full") {
12
12
  let template;
13
13
  switch(format){
14
- case 'day':
15
- template = 'DD MMM YYYY'; // 17 Aug 2021
14
+ case "day":
15
+ template = "DD MMM YYYY"; // 17 Aug 2021
16
16
  break;
17
- case 'weekday':
18
- template = 'ddd, DD MMM'; // Tue, 17 Aug
17
+ case "weekday":
18
+ template = "ddd, DD MMM"; // Tue, 17 Aug
19
19
  break;
20
- case 'time':
21
- template = 'h:mm A'; // 3:45 PM
20
+ case "time":
21
+ template = "h:mm A"; // 3:45 PM
22
22
  break;
23
- case 'fullWithSeconds':
24
- template = 'ddd, DD MMM YYYY [at] h:mm:ss A'; // Tue, 17 Aug 2021 at 3:45:67 PM
23
+ case "fullWithSeconds":
24
+ template = "ddd, DD MMM YYYY [at] h:mm:ss A"; // Tue, 17 Aug 2021 at 3:45:67 PM
25
25
  break;
26
26
  default:
27
- template = 'ddd, DD MMM YYYY [at] h:mm A';
27
+ template = "ddd, DD MMM YYYY [at] h:mm A";
28
28
  }
29
- return $fUYts$dayjs(date).format(template);
29
+ return (0, $fUYts$dayjs)(date).format(template);
30
30
  }
31
- function $ee655ad1301c8997$export$5fb913e47d486079(date, format = 'full') {
31
+ function $ee655ad1301c8997$export$5fb913e47d486079(date, format = "full") {
32
32
  let template;
33
33
  switch(format){
34
- case 'day':
35
- template = 'YYYY-MM-DD'; // 2019-08-24
34
+ case "day":
35
+ template = "YYYY-MM-DD"; // 2019-08-24
36
36
  break;
37
- case 'weekday':
38
- template = 'MM-DD'; // 08-24
37
+ case "weekday":
38
+ template = "MM-DD"; // 08-24
39
39
  break;
40
- case 'time':
41
- template = 'HH:mm:ss.SSS'; // 15:44:07.000
40
+ case "time":
41
+ template = "HH:mm:ss.SSS"; // 15:44:07.000
42
42
  break;
43
43
  default:
44
- template = 'YYYY-MM-DDTHH:mm:ss.SSS[Z]';
44
+ template = "YYYY-MM-DDTHH:mm:ss.SSS[Z]";
45
45
  }
46
- return $fUYts$dayjs(date).utc().format(template);
46
+ return (0, $fUYts$dayjs)(date).utc().format(template);
47
47
  }
48
48
  const $ee655ad1301c8997$export$3ae94a2503e890a1 = (date)=>{
49
- return $ee655ad1301c8997$export$de4eb09f10f9c95e(date, 'day');
49
+ return $ee655ad1301c8997$export$de4eb09f10f9c95e(date, "day");
50
50
  };
51
51
  const $ee655ad1301c8997$export$3203edd9e5edd663 = (date)=>{
52
- return $ee655ad1301c8997$export$de4eb09f10f9c95e(date, 'time');
52
+ return $ee655ad1301c8997$export$de4eb09f10f9c95e(date, "time");
53
53
  };
54
54
  const $ee655ad1301c8997$export$b89623867a65b725 = (date)=>{
55
- return $ee655ad1301c8997$export$de4eb09f10f9c95e(date, 'weekday');
55
+ return $ee655ad1301c8997$export$de4eb09f10f9c95e(date, "weekday");
56
56
  };
57
57
 
58
58
 
59
59
 
60
60
 
61
61
 
62
- $fUYts$dayjs.extend($fUYts$dayjspluginutc);
63
- $fUYts$dayjs.extend($fUYts$dayjspluginrelativeTime);
64
- $fUYts$dayjs.extend($fUYts$dayjsplugincalendar);
62
+ (0, $fUYts$dayjs).extend((0, $fUYts$dayjspluginutc));
63
+ (0, $fUYts$dayjs).extend((0, $fUYts$dayjspluginrelativeTime));
64
+ (0, $fUYts$dayjs).extend((0, $fUYts$dayjsplugincalendar));
65
65
  function $162585a33f185f78$export$68534c3ecebfa124(date, baseDate = new Date()) {
66
- return $fUYts$dayjs(date).from(baseDate);
66
+ return (0, $fUYts$dayjs)(date).from(baseDate);
67
67
  }
68
68
  function $162585a33f185f78$export$aa1a2def90bfd930(date, baseDate = new Date()) {
69
- const isToday = $fUYts$dayjs(date).isSame(baseDate, 'day');
69
+ const isToday = (0, $fUYts$dayjs)(date).isSame(baseDate, "day");
70
70
  if (!isToday) // if the date is not today, we display it with "Yesterday", "Tomorrow", etc.
71
71
  // and if the date is not in the current week then it will display "17 Aug 2021"
72
- return $fUYts$dayjs(date).calendar(baseDate, {
73
- sameElse: 'DD MMM YYYY'
72
+ return (0, $fUYts$dayjs)(date).calendar(baseDate, {
73
+ sameElse: "DD MMM YYYY"
74
74
  });
75
75
  // returns "... ago"
76
76
  return $162585a33f185f78$export$68534c3ecebfa124(date, baseDate);
@@ -78,16 +78,16 @@ function $162585a33f185f78$export$aa1a2def90bfd930(date, baseDate = new Date())
78
78
 
79
79
 
80
80
 
81
- const $02aa7794cdab25f9$var$_DateTime = ({ date: date , format: format = 'full' , testId: testId = 'cf-ui-date-time' , ...otherProps }, ref)=>{
82
- const machineReadableDate = $ee655ad1301c8997$export$5fb913e47d486079(date);
83
- return /*#__PURE__*/ $fUYts$react.createElement("time", {
81
+ const $02aa7794cdab25f9$var$_DateTime = ({ date: date , format: format = "full" , testId: testId = "cf-ui-date-time" , ...otherProps }, ref)=>{
82
+ const machineReadableDate = (0, $ee655ad1301c8997$export$5fb913e47d486079)(date);
83
+ return /*#__PURE__*/ (0, $fUYts$react).createElement("time", {
84
84
  dateTime: machineReadableDate,
85
85
  "data-test-id": testId,
86
86
  ...otherProps,
87
87
  ref: ref
88
- }, $ee655ad1301c8997$export$de4eb09f10f9c95e(date, format));
88
+ }, (0, $ee655ad1301c8997$export$de4eb09f10f9c95e)(date, format));
89
89
  };
90
- const $02aa7794cdab25f9$export$82f9ebd9adeba146 = /*#__PURE__*/ $fUYts$react.forwardRef($02aa7794cdab25f9$var$_DateTime);
90
+ const $02aa7794cdab25f9$export$82f9ebd9adeba146 = /*#__PURE__*/ (0, $fUYts$react).forwardRef($02aa7794cdab25f9$var$_DateTime);
91
91
 
92
92
 
93
93
 
@@ -96,31 +96,31 @@ const $02aa7794cdab25f9$export$82f9ebd9adeba146 = /*#__PURE__*/ $fUYts$react.for
96
96
 
97
97
 
98
98
 
99
- $fUYts$dayjs.extend($fUYts$dayjspluginutc);
100
- $fUYts$dayjs.extend($fUYts$dayjspluginrelativeTime);
101
- $fUYts$dayjs.extend($fUYts$dayjsplugincalendar);
102
- const $f5a0093d268a4b59$var$_RelativeDateTime = ({ date: date , baseDate: baseDate , isRelativeToCurrentWeek: isRelativeToCurrentWeek = false , testId: testId = 'cf-ui-relative-date-time' , ...otherProps }, ref)=>{
99
+ (0, $fUYts$dayjs).extend((0, $fUYts$dayjspluginutc));
100
+ (0, $fUYts$dayjs).extend((0, $fUYts$dayjspluginrelativeTime));
101
+ (0, $fUYts$dayjs).extend((0, $fUYts$dayjsplugincalendar));
102
+ const $f5a0093d268a4b59$var$_RelativeDateTime = ({ date: date , baseDate: baseDate , isRelativeToCurrentWeek: isRelativeToCurrentWeek = false , testId: testId = "cf-ui-relative-date-time" , ...otherProps }, ref)=>{
103
103
  const now = new Date();
104
104
  const referenceDate = baseDate !== null && baseDate !== void 0 ? baseDate : now;
105
- const dayjsDate = $fUYts$dayjs(date);
106
- const machineReadableDate = $ee655ad1301c8997$export$5fb913e47d486079(date);
105
+ const dayjsDate = (0, $fUYts$dayjs)(date);
106
+ const machineReadableDate = (0, $ee655ad1301c8997$export$5fb913e47d486079)(date);
107
107
  let relativeDate;
108
- if (isRelativeToCurrentWeek && !dayjsDate.isSame(referenceDate, 'day')) /**
108
+ if (isRelativeToCurrentWeek && !dayjsDate.isSame(referenceDate, "day")) /**
109
109
  * if isRelativeToCurrentWeek is true and the date is not today, we display the date with Yesterday, Tomorrow, etc
110
110
  * or, if the date is not in the current week, it displays "17 Aug 2021"
111
111
  *
112
112
  * check formatRelativeToCurrentWeekDateTime for more details
113
- */ relativeDate = $162585a33f185f78$export$aa1a2def90bfd930(date, referenceDate);
113
+ */ relativeDate = (0, $162585a33f185f78$export$aa1a2def90bfd930)(date, referenceDate);
114
114
  else // otherwise we display it with "... ago" or "in ..." notation
115
- relativeDate = $162585a33f185f78$export$68534c3ecebfa124(date, referenceDate);
116
- return /*#__PURE__*/ $fUYts$react.createElement("time", {
115
+ relativeDate = (0, $162585a33f185f78$export$68534c3ecebfa124)(date, referenceDate);
116
+ return /*#__PURE__*/ (0, $fUYts$react).createElement("time", {
117
117
  dateTime: machineReadableDate,
118
118
  "data-test-id": testId,
119
119
  ...otherProps,
120
120
  ref: ref
121
121
  }, relativeDate);
122
122
  };
123
- const $f5a0093d268a4b59$export$6de14fd95adb1c8a = /*#__PURE__*/ $fUYts$react.forwardRef($f5a0093d268a4b59$var$_RelativeDateTime);
123
+ const $f5a0093d268a4b59$export$6de14fd95adb1c8a = /*#__PURE__*/ (0, $fUYts$react).forwardRef($f5a0093d268a4b59$var$_RelativeDateTime);
124
124
 
125
125
 
126
126
 
@@ -1 +1 @@
1
- {"mappings":";;;;;;ACAA;AEAA;;AAEA4B,YAAK,CAACE,MAAN,CAAaD,qBAAb,CAAAD,CAAAA;AAmBO,SAASxB,yCAAT,CACLU,IADK,EAELC,MAAkB,GAAG,MAFhB,EAGG;IACR,IAAIgB,QAAQ,AAAZ,AAAA;IAEA,OAAQhB,MAAR;QACE,KAAK,KAAL;YACE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;","sources":["packages/components/datetime/src/index.ts","packages/components/datetime/src/DateTime/DateTime.tsx","packages/components/datetime/src/utils/index.ts","packages/components/datetime/src/utils/formatDateTimeUtils.ts","packages/components/datetime/src/utils/relativeDateTimeUtils.ts","packages/components/datetime/src/RelativeDateTime/RelativeDateTime.tsx"],"sourcesContent":["export { DateTime } from './DateTime/DateTime';\nexport type { DateTimeProps } from './DateTime/DateTime';\nexport { RelativeDateTime } from './RelativeDateTime/RelativeDateTime';\nexport type { RelativeDateTimeProps } from './RelativeDateTime/RelativeDateTime';\nexport {\n formatDateAndTime,\n formatMachineReadableDateTime,\n formatRelativeDateTime,\n} from './utils';\n","import React from 'react';\nimport type {\n CommonProps,\n PropsWithHTMLElement,\n ExpandProps,\n} from '@contentful/f36-core';\n\nimport type { DateType, DateFormat } from '../types';\nimport { formatDateAndTime, formatMachineReadableDateTime } from '../utils';\n\ninterface DateTimeOwnProps extends CommonProps {\n /**\n * The date that will be displayed. It accepts a JS Date, an ISO8601 Timestamp string, or Unix Epoch Milliseconds number\n */\n date: DateType;\n /**\n * The format in which the date will be presented\n *\n * @default full\n **/\n format?: DateFormat;\n}\n\nexport type DateTimeProps = PropsWithHTMLElement<DateTimeOwnProps, 'time'>;\n\nconst _DateTime = (\n {\n date,\n format = 'full',\n testId = 'cf-ui-date-time',\n ...otherProps\n }: ExpandProps<DateTimeProps>,\n ref: React.Ref<HTMLTimeElement>,\n) => {\n const machineReadableDate = formatMachineReadableDateTime(date);\n\n return (\n <time\n dateTime={machineReadableDate}\n data-test-id={testId}\n {...otherProps}\n ref={ref}\n >\n {formatDateAndTime(date, format)}\n </time>\n );\n};\n\n/**\n * The DateTime component will format a date to a human friendly format and wrap it in a `<time>` tag\n */\nexport const DateTime = React.forwardRef(_DateTime);\n","export {\n formatDateAndTime,\n formatMachineReadableDateTime,\n formatDate,\n formatTime,\n formatWeekdayDate,\n} from './formatDateTimeUtils';\n\nexport {\n formatRelativeDateTime,\n formatRelativeToCurrentWeekDateTime,\n} from './relativeDateTimeUtils';\n","import dayjs from 'dayjs';\nimport utcPlugin from 'dayjs/plugin/utc';\ndayjs.extend(utcPlugin);\n\nimport type { DateType, DateFormat } from '../types';\n\n/**\n * A funtion that will return a formatted date string. The format will dependend on the option\n * passed in the second argument.\n * By default, it will return a string with Forma 36’s \"full\" format (e.g. Tue, 17 Aug 2021 at 3:45 PM)\n *\n * @param {DateType} date - the date to be formatted\n * @param {DateFormat} format - the desired format (\"full\", \"day\", \"weekday\", or \"time\")\n * @returns a formatted date\n *\n * @example\n * formatDateAndTime('2021-08-17T15:45:00') // returns \"Tue, 17 Aug 2021 at 3:45 PM\"\n *\n * @example\n * formatDateAndTime('2021-08-17T15:45:00', 'day') // returns \"17 Aug 2021\"\n */\nexport function formatDateAndTime(\n date: DateType,\n format: DateFormat = 'full',\n): string {\n let template: string;\n\n switch (format) {\n case 'day':\n template = 'DD MMM YYYY'; // 17 Aug 2021\n break;\n case 'weekday':\n template = 'ddd, DD MMM'; // Tue, 17 Aug\n break;\n case 'time':\n template = 'h:mm A'; // 3:45 PM\n break;\n case 'fullWithSeconds':\n template = 'ddd, DD MMM YYYY [at] h:mm:ss A'; // Tue, 17 Aug 2021 at 3:45:67 PM\n break;\n default:\n template = 'ddd, DD MMM YYYY [at] h:mm A'; // Tue, 17 Aug 2021 at 3:45 PM\n }\n\n return dayjs(date).format(template);\n}\n\n/**\n * A funtion that will return a machine-readable date string that should be passed to the `datetime` attribute of a `<time>` tag\n * By default, it will return a string with \"YYYY-MM-DDTHH:mm:ss.SSS[Z]\" format\n *\n * @param {DateType} date - the date to be formatted\n * @param {DateFormat} format - the desired format (\"full\", \"day\", \"weekday\", or \"time\")\n * @returns a formatted date\n *\n * @example\n * formatMachineReadableDateTime(date) // returns 2019-08-13T10:00:00.000Z\n *\n * @example\n * formatMachineReadableDateTime(date, 'day') // returns 2019-08-13\n */\nexport function formatMachineReadableDateTime(\n date: DateType,\n format: DateFormat = 'full',\n): string {\n let template: string;\n\n switch (format) {\n case 'day':\n template = 'YYYY-MM-DD'; // 2019-08-24\n break;\n case 'weekday':\n template = 'MM-DD'; // 08-24\n break;\n case 'time':\n template = 'HH:mm:ss.SSS'; // 15:44:07.000\n break;\n default:\n template = 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'; // 2019-08-24T15:44:07.000Z\n }\n\n return dayjs(date).utc().format(template);\n}\n\n/**\n * @example\n * > formatDate(date)\n * 13 Aug 2019\n */\nexport const formatDate = (date: DateType): string => {\n return formatDateAndTime(date, 'day');\n};\n\n/**\n * @example\n * > formatTime(date)\n * 8:00 AM\n */\nexport const formatTime = (date: DateType): string => {\n return formatDateAndTime(date, 'time');\n};\n\n/**\n * @example\n * > formatWeekdayDate(date)\n * Mon, 12 Aug\n */\nexport const formatWeekdayDate = (date: DateType): string => {\n return formatDateAndTime(date, 'weekday');\n};\n","import dayjs from 'dayjs';\nimport utcPlugin from 'dayjs/plugin/utc';\nimport relativeTime from 'dayjs/plugin/relativeTime';\nimport calendarPlugin from 'dayjs/plugin/calendar';\ndayjs.extend(utcPlugin);\ndayjs.extend(relativeTime);\ndayjs.extend(calendarPlugin);\n\nimport type { DateType } from '../types';\n\n/**\n * A function that will return a string with how far a given date is in the past or future,\n * using a baseDate as reference. If the baseDate is not passed, the function will use today as reference.\n *\n * @param {DateType} date - the date to be formatted\n * @param {DateFormat} baseDate - the date that should be used as a reference (default is \"today\")\n * @returns a relative date\n *\n * @example\n * // Considering today as 18.08.2021\n * formatRelativeDateTime('2021-08-17T15:45:00') // returns \"a day ago\"\n *\n * @example\n * formatRelativeDateTime('2021-08-17T15:45:00', '2021-08-16') // returns \"in a day\"\n */\nexport function formatRelativeDateTime(\n date: DateType,\n baseDate: DateType = new Date(),\n) {\n return dayjs(date).from(baseDate);\n}\n\n/**\n * A function that formats a date relative to Today or to the `baseDate` if passed.\n * If the date is not today, it will return a string with \"Yesterday ...\", \"Tomorrow ...\", etc\n * If the date is not in the current week, it return a string with \"DD MMM YYYY\" format\n * If the date is today, it will return a string with \"... ago\" or \"in ...\"\n *\n * @param {DateType} date - the date to be formatted\n * @param {DateFormat} baseDate - the date that should be used as a reference (default is \"today\")\n * @returns a relative date\n *\n * @example\n * // Considering today as 18.08.2021\n * formatRelativeToCurrentWeekDateTime('2021-08-17T15:45:00') // returns \"Yesterday at 3:45 PM\"\n *\n * @example\n * formatRelativeToCurrentWeekDateTime('2021-08-17T15:45:00', '2021-08-16') // returns \"Tomorrow at 3:45 PM\"\n */\nexport function formatRelativeToCurrentWeekDateTime(\n date: DateType,\n baseDate: DateType = new Date(),\n) {\n const isToday = dayjs(date).isSame(baseDate, 'day');\n\n if (!isToday) {\n // if the date is not today, we display it with \"Yesterday\", \"Tomorrow\", etc.\n // and if the date is not in the current week then it will display \"17 Aug 2021\"\n return dayjs(date).calendar(baseDate, {\n sameElse: 'DD MMM YYYY',\n });\n }\n\n // returns \"... ago\"\n return formatRelativeDateTime(date, baseDate);\n}\n","import React from 'react';\nimport type {\n CommonProps,\n PropsWithHTMLElement,\n ExpandProps,\n} from '@contentful/f36-core';\n\nimport dayjs from 'dayjs';\nimport utcPlugin from 'dayjs/plugin/utc';\nimport relativeTime from 'dayjs/plugin/relativeTime';\nimport calendarPlugin from 'dayjs/plugin/calendar';\ndayjs.extend(utcPlugin);\ndayjs.extend(relativeTime);\ndayjs.extend(calendarPlugin);\n\nimport type { DateType } from '../types';\nimport {\n formatMachineReadableDateTime,\n formatRelativeDateTime,\n formatRelativeToCurrentWeekDateTime,\n} from '../utils';\n\ninterface RelativeDateTimeInternalProps extends CommonProps {\n /**\n * The date that will be displayed. It accepts a JS Date, an ISO8601 Timestamp string, or Unix Epoch Milliseconds number\n */\n date: DateType;\n /**\n * If a value is passed to baseDate, then the component will compare both dates and return the time between them.\n * If no value is passed then the date will be compared to \"now\"\n *\n * @default \"Now\"\n */\n baseDate?: DateType;\n /**\n * Sets the date to be relative only if it is in the current week\n * @default false\n */\n isRelativeToCurrentWeek?: boolean;\n}\n\nexport type RelativeDateTimeProps = PropsWithHTMLElement<\n RelativeDateTimeInternalProps,\n 'time'\n>;\n\nconst _RelativeDateTime = (\n {\n date,\n baseDate,\n isRelativeToCurrentWeek = false,\n testId = 'cf-ui-relative-date-time',\n ...otherProps\n }: ExpandProps<RelativeDateTimeProps>,\n ref: React.Ref<HTMLTimeElement>,\n) => {\n const now = new Date();\n const referenceDate = baseDate ?? now;\n const dayjsDate = dayjs(date);\n const machineReadableDate = formatMachineReadableDateTime(date);\n\n let relativeDate: string;\n\n if (isRelativeToCurrentWeek && !dayjsDate.isSame(referenceDate, 'day')) {\n /**\n * if isRelativeToCurrentWeek is true and the date is not today, we display the date with Yesterday, Tomorrow, etc\n * or, if the date is not in the current week, it displays \"17 Aug 2021\"\n *\n * check formatRelativeToCurrentWeekDateTime for more details\n */\n relativeDate = formatRelativeToCurrentWeekDateTime(date, referenceDate);\n } else {\n // otherwise we display it with \"... ago\" or \"in ...\" notation\n relativeDate = formatRelativeDateTime(date, referenceDate);\n }\n\n return (\n <time\n dateTime={machineReadableDate}\n data-test-id={testId}\n {...otherProps}\n ref={ref}\n >\n {relativeDate}\n </time>\n );\n};\n\n/**\n * The RelativeDateTime will show a `date` relative to \"now\" or to the `baseDate`\n * (e.g. in a day, in one month, one month ago, etc).\n */\nexport const RelativeDateTime = React.forwardRef(_RelativeDateTime);\n"],"names":["DateTime","DateTimeProps","RelativeDateTime","RelativeDateTimeProps","formatDateAndTime","formatMachineReadableDateTime","formatRelativeDateTime","React","CommonProps","PropsWithHTMLElement","ExpandProps","DateType","DateFormat","DateTimeOwnProps","date","format","_DateTime","testId","otherProps","ref","Ref","HTMLTimeElement","machineReadableDate","forwardRef","formatDate","formatTime","formatWeekdayDate","formatRelativeToCurrentWeekDateTime","dayjs","utcPlugin","extend","template","utc","relativeTime","calendarPlugin","baseDate","Date","from","isToday","isSame","calendar","sameElse","RelativeDateTimeInternalProps","isRelativeToCurrentWeek","_RelativeDateTime","now","referenceDate","dayjsDate","relativeDate"],"version":3,"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C,AAAA;IACA,MAAME,SAAS,GAAGnB,CAAAA,GAAAA,YAAK,CAAA,CAACd,IAAD,CAAvB,AAAA;IACA,MAAMQ,mBAAmB,GAAGjB,CAAAA,GAAAA,yCAA6B,CAAA,CAACS,IAAD,CAAzD,AAAA;IAEA,IAAIkC,YAAY,AAAhB,AAAA;IAEA,IAAIL,uBAAuB,IAAI,CAACI,SAAS,CAACR,MAAV,CAAiBO,aAAjB,EAAgC,KAAhC,CAAhC,EACE;;;;;OAKJ,CACIE,YAAY,GAAGrB,CAAAA,GAAAA,yCAAmC,CAAA,CAACb,IAAD,EAAOgC,aAAP,CAAlD,CAAAE;SAEA,8DAAA;IACAA,YAAY,GAAG1C,CAAAA,GAAAA,yCAAsB,CAAA,CAACQ,IAAD,EAAOgC,aAAP,CAArC,CAAAE;IAGF,qBACE,gCAAC,MAAD;QACE,QAAA,EAAU1B,mBAAD;QACT,cAAA,EAAcL,MAAD;QACb,GAAIC,UAAJ;QACA,GAAA,EAAKC,GAAD;OAEH6B,YAAD,CAPJ,CAQF;CAtCA,AAwCC;AAMM,MAAM9C,yCAAgB,iBAAGK,CAAAA,GAAAA,YAAK,CAAA,CAACgB,UAAN,CAAiBqB,uCAAjB,CAAzB,AAAP;","sources":["packages/components/datetime/src/index.ts","packages/components/datetime/src/DateTime/DateTime.tsx","packages/components/datetime/src/utils/index.ts","packages/components/datetime/src/utils/formatDateTimeUtils.ts","packages/components/datetime/src/utils/relativeDateTimeUtils.ts","packages/components/datetime/src/RelativeDateTime/RelativeDateTime.tsx"],"sourcesContent":["export { DateTime } from './DateTime/DateTime';\nexport type { DateTimeProps } from './DateTime/DateTime';\nexport { RelativeDateTime } from './RelativeDateTime/RelativeDateTime';\nexport type { RelativeDateTimeProps } from './RelativeDateTime/RelativeDateTime';\nexport {\n formatDateAndTime,\n formatMachineReadableDateTime,\n formatRelativeDateTime,\n} from './utils';\n","import React from 'react';\nimport type {\n CommonProps,\n PropsWithHTMLElement,\n ExpandProps,\n} from '@contentful/f36-core';\n\nimport type { DateType, DateFormat } from '../types';\nimport { formatDateAndTime, formatMachineReadableDateTime } from '../utils';\n\ninterface DateTimeOwnProps extends CommonProps {\n /**\n * The date that will be displayed. It accepts a JS Date, an ISO8601 Timestamp string, or Unix Epoch Milliseconds number\n */\n date: DateType;\n /**\n * The format in which the date will be presented\n *\n * @default full\n **/\n format?: DateFormat;\n}\n\nexport type DateTimeProps = PropsWithHTMLElement<DateTimeOwnProps, 'time'>;\n\nconst _DateTime = (\n {\n date,\n format = 'full',\n testId = 'cf-ui-date-time',\n ...otherProps\n }: ExpandProps<DateTimeProps>,\n ref: React.Ref<HTMLTimeElement>,\n) => {\n const machineReadableDate = formatMachineReadableDateTime(date);\n\n return (\n <time\n dateTime={machineReadableDate}\n data-test-id={testId}\n {...otherProps}\n ref={ref}\n >\n {formatDateAndTime(date, format)}\n </time>\n );\n};\n\n/**\n * The DateTime component will format a date to a human friendly format and wrap it in a `<time>` tag\n */\nexport const DateTime = React.forwardRef(_DateTime);\n","export {\n formatDateAndTime,\n formatMachineReadableDateTime,\n formatDate,\n formatTime,\n formatWeekdayDate,\n} from './formatDateTimeUtils';\n\nexport {\n formatRelativeDateTime,\n formatRelativeToCurrentWeekDateTime,\n} from './relativeDateTimeUtils';\n","import dayjs from 'dayjs';\nimport utcPlugin from 'dayjs/plugin/utc';\ndayjs.extend(utcPlugin);\n\nimport type { DateType, DateFormat } from '../types';\n\n/**\n * A funtion that will return a formatted date string. The format will dependend on the option\n * passed in the second argument.\n * By default, it will return a string with Forma 36’s \"full\" format (e.g. Tue, 17 Aug 2021 at 3:45 PM)\n *\n * @param {DateType} date - the date to be formatted\n * @param {DateFormat} format - the desired format (\"full\", \"day\", \"weekday\", or \"time\")\n * @returns a formatted date\n *\n * @example\n * formatDateAndTime('2021-08-17T15:45:00') // returns \"Tue, 17 Aug 2021 at 3:45 PM\"\n *\n * @example\n * formatDateAndTime('2021-08-17T15:45:00', 'day') // returns \"17 Aug 2021\"\n */\nexport function formatDateAndTime(\n date: DateType,\n format: DateFormat = 'full',\n): string {\n let template: string;\n\n switch (format) {\n case 'day':\n template = 'DD MMM YYYY'; // 17 Aug 2021\n break;\n case 'weekday':\n template = 'ddd, DD MMM'; // Tue, 17 Aug\n break;\n case 'time':\n template = 'h:mm A'; // 3:45 PM\n break;\n case 'fullWithSeconds':\n template = 'ddd, DD MMM YYYY [at] h:mm:ss A'; // Tue, 17 Aug 2021 at 3:45:67 PM\n break;\n default:\n template = 'ddd, DD MMM YYYY [at] h:mm A'; // Tue, 17 Aug 2021 at 3:45 PM\n }\n\n return dayjs(date).format(template);\n}\n\n/**\n * A funtion that will return a machine-readable date string that should be passed to the `datetime` attribute of a `<time>` tag\n * By default, it will return a string with \"YYYY-MM-DDTHH:mm:ss.SSS[Z]\" format\n *\n * @param {DateType} date - the date to be formatted\n * @param {DateFormat} format - the desired format (\"full\", \"day\", \"weekday\", or \"time\")\n * @returns a formatted date\n *\n * @example\n * formatMachineReadableDateTime(date) // returns 2019-08-13T10:00:00.000Z\n *\n * @example\n * formatMachineReadableDateTime(date, 'day') // returns 2019-08-13\n */\nexport function formatMachineReadableDateTime(\n date: DateType,\n format: DateFormat = 'full',\n): string {\n let template: string;\n\n switch (format) {\n case 'day':\n template = 'YYYY-MM-DD'; // 2019-08-24\n break;\n case 'weekday':\n template = 'MM-DD'; // 08-24\n break;\n case 'time':\n template = 'HH:mm:ss.SSS'; // 15:44:07.000\n break;\n default:\n template = 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'; // 2019-08-24T15:44:07.000Z\n }\n\n return dayjs(date).utc().format(template);\n}\n\n/**\n * @example\n * > formatDate(date)\n * 13 Aug 2019\n */\nexport const formatDate = (date: DateType): string => {\n return formatDateAndTime(date, 'day');\n};\n\n/**\n * @example\n * > formatTime(date)\n * 8:00 AM\n */\nexport const formatTime = (date: DateType): string => {\n return formatDateAndTime(date, 'time');\n};\n\n/**\n * @example\n * > formatWeekdayDate(date)\n * Mon, 12 Aug\n */\nexport const formatWeekdayDate = (date: DateType): string => {\n return formatDateAndTime(date, 'weekday');\n};\n","import dayjs from 'dayjs';\nimport utcPlugin from 'dayjs/plugin/utc';\nimport relativeTime from 'dayjs/plugin/relativeTime';\nimport calendarPlugin from 'dayjs/plugin/calendar';\ndayjs.extend(utcPlugin);\ndayjs.extend(relativeTime);\ndayjs.extend(calendarPlugin);\n\nimport type { DateType } from '../types';\n\n/**\n * A function that will return a string with how far a given date is in the past or future,\n * using a baseDate as reference. If the baseDate is not passed, the function will use today as reference.\n *\n * @param {DateType} date - the date to be formatted\n * @param {DateFormat} baseDate - the date that should be used as a reference (default is \"today\")\n * @returns a relative date\n *\n * @example\n * // Considering today as 18.08.2021\n * formatRelativeDateTime('2021-08-17T15:45:00') // returns \"a day ago\"\n *\n * @example\n * formatRelativeDateTime('2021-08-17T15:45:00', '2021-08-16') // returns \"in a day\"\n */\nexport function formatRelativeDateTime(\n date: DateType,\n baseDate: DateType = new Date(),\n) {\n return dayjs(date).from(baseDate);\n}\n\n/**\n * A function that formats a date relative to Today or to the `baseDate` if passed.\n * If the date is not today, it will return a string with \"Yesterday ...\", \"Tomorrow ...\", etc\n * If the date is not in the current week, it return a string with \"DD MMM YYYY\" format\n * If the date is today, it will return a string with \"... ago\" or \"in ...\"\n *\n * @param {DateType} date - the date to be formatted\n * @param {DateFormat} baseDate - the date that should be used as a reference (default is \"today\")\n * @returns a relative date\n *\n * @example\n * // Considering today as 18.08.2021\n * formatRelativeToCurrentWeekDateTime('2021-08-17T15:45:00') // returns \"Yesterday at 3:45 PM\"\n *\n * @example\n * formatRelativeToCurrentWeekDateTime('2021-08-17T15:45:00', '2021-08-16') // returns \"Tomorrow at 3:45 PM\"\n */\nexport function formatRelativeToCurrentWeekDateTime(\n date: DateType,\n baseDate: DateType = new Date(),\n) {\n const isToday = dayjs(date).isSame(baseDate, 'day');\n\n if (!isToday) {\n // if the date is not today, we display it with \"Yesterday\", \"Tomorrow\", etc.\n // and if the date is not in the current week then it will display \"17 Aug 2021\"\n return dayjs(date).calendar(baseDate, {\n sameElse: 'DD MMM YYYY',\n });\n }\n\n // returns \"... ago\"\n return formatRelativeDateTime(date, baseDate);\n}\n","import React from 'react';\nimport type {\n CommonProps,\n PropsWithHTMLElement,\n ExpandProps,\n} from '@contentful/f36-core';\n\nimport dayjs from 'dayjs';\nimport utcPlugin from 'dayjs/plugin/utc';\nimport relativeTime from 'dayjs/plugin/relativeTime';\nimport calendarPlugin from 'dayjs/plugin/calendar';\ndayjs.extend(utcPlugin);\ndayjs.extend(relativeTime);\ndayjs.extend(calendarPlugin);\n\nimport type { DateType } from '../types';\nimport {\n formatMachineReadableDateTime,\n formatRelativeDateTime,\n formatRelativeToCurrentWeekDateTime,\n} from '../utils';\n\ninterface RelativeDateTimeInternalProps extends CommonProps {\n /**\n * The date that will be displayed. It accepts a JS Date, an ISO8601 Timestamp string, or Unix Epoch Milliseconds number\n */\n date: DateType;\n /**\n * If a value is passed to baseDate, then the component will compare both dates and return the time between them.\n * If no value is passed then the date will be compared to \"now\"\n *\n * @default \"Now\"\n */\n baseDate?: DateType;\n /**\n * Sets the date to be relative only if it is in the current week\n * @default false\n */\n isRelativeToCurrentWeek?: boolean;\n}\n\nexport type RelativeDateTimeProps = PropsWithHTMLElement<\n RelativeDateTimeInternalProps,\n 'time'\n>;\n\nconst _RelativeDateTime = (\n {\n date,\n baseDate,\n isRelativeToCurrentWeek = false,\n testId = 'cf-ui-relative-date-time',\n ...otherProps\n }: ExpandProps<RelativeDateTimeProps>,\n ref: React.Ref<HTMLTimeElement>,\n) => {\n const now = new Date();\n const referenceDate = baseDate ?? now;\n const dayjsDate = dayjs(date);\n const machineReadableDate = formatMachineReadableDateTime(date);\n\n let relativeDate: string;\n\n if (isRelativeToCurrentWeek && !dayjsDate.isSame(referenceDate, 'day')) {\n /**\n * if isRelativeToCurrentWeek is true and the date is not today, we display the date with Yesterday, Tomorrow, etc\n * or, if the date is not in the current week, it displays \"17 Aug 2021\"\n *\n * check formatRelativeToCurrentWeekDateTime for more details\n */\n relativeDate = formatRelativeToCurrentWeekDateTime(date, referenceDate);\n } else {\n // otherwise we display it with \"... ago\" or \"in ...\" notation\n relativeDate = formatRelativeDateTime(date, referenceDate);\n }\n\n return (\n <time\n dateTime={machineReadableDate}\n data-test-id={testId}\n {...otherProps}\n ref={ref}\n >\n {relativeDate}\n </time>\n );\n};\n\n/**\n * The RelativeDateTime will show a `date` relative to \"now\" or to the `baseDate`\n * (e.g. in a day, in one month, one month ago, etc).\n */\nexport const RelativeDateTime = React.forwardRef(_RelativeDateTime);\n"],"names":["DateTime","DateTimeProps","RelativeDateTime","RelativeDateTimeProps","formatDateAndTime","formatMachineReadableDateTime","formatRelativeDateTime","React","CommonProps","PropsWithHTMLElement","ExpandProps","DateType","DateFormat","DateTimeOwnProps","date","format","_DateTime","testId","otherProps","ref","Ref","HTMLTimeElement","machineReadableDate","forwardRef","formatDate","formatTime","formatWeekdayDate","formatRelativeToCurrentWeekDateTime","dayjs","utcPlugin","extend","template","utc","relativeTime","calendarPlugin","baseDate","Date","from","isToday","isSame","calendar","sameElse","RelativeDateTimeInternalProps","isRelativeToCurrentWeek","_RelativeDateTime","now","referenceDate","dayjsDate","relativeDate"],"version":3,"file":"module.js.map"}
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@contentful/f36-datetime",
3
- "version": "4.12.0",
3
+ "version": "4.15.0",
4
4
  "description": "Forma 36: DateTime component",
5
5
  "scripts": {
6
6
  "build": "parcel build"
7
7
  },
8
8
  "dependencies": {
9
9
  "@babel/runtime": "^7.6.2",
10
- "@contentful/f36-core": "^4.12.0",
10
+ "@contentful/f36-core": "^4.15.0",
11
11
  "@contentful/f36-tokens": "^4.0.1",
12
12
  "dayjs": "^1.10.6",
13
13
  "emotion": "^10.0.17"