dce-reactkit 4.2.2 → 4.2.4-beta-timestamp.1

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.
@@ -9,6 +9,7 @@ type Props = {
9
9
  topRightChildren?: React.ReactNode;
10
10
  noBottomMargin?: boolean;
11
11
  noBottomPadding?: boolean;
12
+ minTitleWidth?: string;
12
13
  };
13
14
  declare const TabBox: React.FC<Props>;
14
15
  export default TabBox;
package/dist/index.d.ts CHANGED
@@ -232,6 +232,7 @@ type Props$k = {
232
232
  topRightChildren?: React$1.ReactNode;
233
233
  noBottomMargin?: boolean;
234
234
  noBottomPadding?: boolean;
235
+ minTitleWidth?: string;
235
236
  };
236
237
  declare const TabBox: React$1.FC<Props$k>;
237
238
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dce-reactkit",
3
- "version": "4.2.2",
3
+ "version": "4.2.4-beta-timestamp.1",
4
4
  "description": "Shared components for Harvard DCE apps",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -21,6 +21,8 @@ type Props = {
21
21
  noBottomMargin?: boolean,
22
22
  // If true, don't add padding to bottom of tab box
23
23
  noBottomPadding?: boolean,
24
+ // Minimum width of the tab part of the box that contains the title (css units)
25
+ minTitleWidth?: string,
24
26
  };
25
27
 
26
28
  /*------------------------------------------------------------------------*/
@@ -121,6 +123,7 @@ const TabBox: React.FC<Props> = (props) => {
121
123
  topRightChildren,
122
124
  noBottomPadding,
123
125
  noBottomMargin,
126
+ minTitleWidth,
124
127
  } = props;
125
128
 
126
129
  /*------------------------------------------------------------------------*/
@@ -134,7 +137,10 @@ const TabBox: React.FC<Props> = (props) => {
134
137
 
135
138
  {/* Title Row with Left and Right sections */}
136
139
  <div className="TabBox-title-container">
137
- <div className="TabBox-title">
140
+ <div
141
+ className="TabBox-title"
142
+ style={{ minWidth: minTitleWidth }}
143
+ >
138
144
  {title}
139
145
  </div>
140
146
  {topRightChildren && (
@@ -36,21 +36,54 @@ const getTimestampFromTimeInfoInET = (
36
36
  minute,
37
37
  } = opts;
38
38
 
39
- // Determine if the date is in DST in Eastern Time
40
- const tempDate = new Date(year, month - 1, day);
41
- const janOffset = new Date(year, 0, 1).getTimezoneOffset();
42
- const isDST = tempDate.getTimezoneOffset() < janOffset;
43
- const etOffset = isDST ? '-04:00' : '-05:00';
44
-
45
39
  // Format with leading zeroes
46
40
  const mm = padZerosLeft(month, 2);
47
41
  const dd = padZerosLeft(day, 2);
48
42
  const hh = padZerosLeft(hour, 2);
49
43
  const min = padZerosLeft(minute, 2);
50
44
 
51
- // Build ET ISO string and convert to UTC timestamp
52
- const etISOString = `${year}-${mm}-${dd}T${hh}:${min}:00${etOffset}`;
53
- const timestamp = (new Date(etISOString)).getTime();
45
+ // Use Intl.DateTimeFormat to get the ET offset for the given date
46
+ const dateForET = new Date(Date.UTC(year, month - 1, day, hour, minute, 0));
47
+ const options: Intl.DateTimeFormatOptions = {
48
+ timeZone: 'America/New_York',
49
+ year: 'numeric',
50
+ month: '2-digit',
51
+ day: '2-digit',
52
+ hour: '2-digit',
53
+ minute: '2-digit',
54
+ second: '2-digit',
55
+ hour12: false,
56
+ };
57
+ const parts: Intl.DateTimeFormatPart[] = new Intl.DateTimeFormat('en-US', options).formatToParts(dateForET);
58
+ const etYear: string | undefined = parts.find((p: Intl.DateTimeFormatPart) => {
59
+ return p.type === 'year';
60
+ })?.value;
61
+ const etMonth: string | undefined = parts.find((p: Intl.DateTimeFormatPart) => {
62
+ return p.type === 'month';
63
+ })?.value;
64
+ const etDay: string | undefined = parts.find((p: Intl.DateTimeFormatPart) => {
65
+ return p.type === 'day';
66
+ })?.value;
67
+ const etHour: string | undefined = parts.find((p: Intl.DateTimeFormatPart) => {
68
+ return p.type === 'hour';
69
+ })?.value;
70
+ const etMinute: string | undefined = parts.find((p: Intl.DateTimeFormatPart) => {
71
+ return p.type === 'minute';
72
+ })?.value;
73
+ const etSecond: string | undefined = parts.find((p: Intl.DateTimeFormatPart) => {
74
+ return p.type === 'second';
75
+ })?.value;
76
+
77
+ // Build ET date string and parse as if local, then get UTC timestamp
78
+ if (!etYear || !etMonth || !etDay || !etHour || !etMinute || !etSecond) {
79
+ throw new ErrorWithCode(
80
+ 'Failed to parse date parts from Intl.DateTimeFormat',
81
+ ReactKitErrorCode.ETTimestampInvalid,
82
+ );
83
+ }
84
+ const etDateString: string = `${etYear}-${etMonth}-${etDay}T${etHour}:${etMinute}:${etSecond}`;
85
+ const etDate: Date = new Date(etDateString);
86
+ const timestamp: number = etDate.getTime();
54
87
 
55
88
  // Verify that the timestamp is correct
56
89
  const timeInfoInET = getTimeInfoInET(timestamp);