Skip to content

Commit 8ab915a

Browse files
authored
fix(cloud9): error when expanding S3 folder #4293
Problem Users on Cloud9-classic (Node.js 16) cannot view the content of an S3 bucket since Toolkit v2.3.0 (#4163). 2024-01-17 13:59:54 [ERROR]: [RangeError: Value longOffset out of range for Intl.DateTimeFormat options property timeZoneName at new DateTimeFormat (<anonymous>) at Sv (/…/dist/src/main.js:2653:1432) Solution: Nodejs 16 only supports `timeZoneName: "short" | "long"`. - Use `timeZoneName="short"` for Cloud9. - Use `timeZoneName="shortOffset"` for VSCode; the "long" format is unnecessarily verbose. - Add tests. - Set a fixed timezone in CI using the $TZ env var. (No other way to force a timezone in Nodejs / javascript.)
1 parent 976fb89 commit 8ab915a

File tree

14 files changed

+47
-12
lines changed

14 files changed

+47
-12
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Cloud9: error when expanding S3 folder"
4+
}

.github/workflows/node.js.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
env:
2222
VSCODE_TEST_VERSION: ${{ matrix.vscode-version }}
2323
NODE_OPTIONS: '--max-old-space-size=8192'
24+
# Set a fixed timezone for tests. Intentionally _not_ UTC.
25+
TZ: 'US/Pacific'
2426
steps:
2527
- uses: actions/checkout@v4
2628
- name: Use Node.js ${{ matrix.node-version }}
@@ -64,6 +66,8 @@ jobs:
6466
env:
6567
VSCODE_TEST_VERSION: ${{ matrix.vscode-version }}
6668
NODE_OPTIONS: '--max-old-space-size=8192'
69+
# Set a fixed timezone for tests. Intentionally _not_ UTC.
70+
TZ: 'US/Pacific'
6771
steps:
6872
- uses: actions/checkout@v4
6973
- name: Use Node.js ${{ matrix.node-version }}

buildspec/linuxE2ETests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ run-as: codebuild-user
55

66
env:
77
variables:
8+
# Set a fixed timezone for tests. Intentionally _not_ UTC.
9+
TZ: 'US/Pacific'
810
AWS_TOOLKIT_TEST_NO_COLOR: '1'
911
NO_COVERAGE: 'true'
1012
# Suppress noisy apt-get/dpkg warnings like "debconf: unable to initialize frontend: Dialog").

buildspec/linuxIntegrationTests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ env:
99
# VSCODE_TEST_VERSION
1010
# GITHUB_READONLY_TOKEN
1111
AWS_TOOLKIT_TEST_NO_COLOR: '1'
12+
# Set a fixed timezone for tests. Intentionally _not_ UTC.
13+
TZ: 'US/Pacific'
1214
NO_COVERAGE: 'true'
1315
# Suppress noisy apt-get/dpkg warnings like "debconf: unable to initialize frontend: Dialog").
1416
DEBIAN_FRONTEND: 'noninteractive'

buildspec/linuxTests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ env:
77
# For "pipefail".
88
shell: bash
99
variables:
10+
# Set a fixed timezone for tests. Intentionally _not_ UTC.
11+
TZ: 'US/Pacific'
1012
AWS_TOOLKIT_TEST_NO_COLOR: '1'
1113

1214
phases:

buildspec/windowsTests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ version: 0.2
22
env:
33
variables:
44
AWS_TOOLKIT_TEST_NO_COLOR: '1'
5+
# Set a fixed timezone for tests. Intentionally _not_ UTC.
6+
TZ: 'US/Pacific'
57
phases:
68
install:
79
runtime-versions:

src/shared/utilities/textUtilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ export function getRelativeDate(from: Date, now: Date = new Date()): string {
246246
* US: Jan 5, 2020 5:30:20 PM GMT-0700
247247
* GB: 5 Jan 2020 17:30:20 GMT+0100
248248
*/
249-
export function formatLocalized(d: Date = new Date()): string {
249+
export function formatLocalized(d: Date = new Date(), cloud9 = isCloud9()): string {
250250
const dateFormat = new Intl.DateTimeFormat('en-US', {
251251
year: 'numeric',
252252
month: 'short',
@@ -256,7 +256,7 @@ export function formatLocalized(d: Date = new Date()): string {
256256
hour: 'numeric',
257257
minute: 'numeric',
258258
second: 'numeric',
259-
timeZoneName: 'longOffset',
259+
timeZoneName: cloud9 ? 'short' : 'shortOffset',
260260
})
261261

262262
return `${dateFormat.format(d)} ${timeFormat.format(d)}`

src/test/cloudWatchLogs/commands/saveCurrentLogDataContent.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ async function testFilterLogEvents(
3636
describe('saveCurrentLogDataContent', async function () {
3737
let filename: string
3838
let tempDir: string
39-
const expectedText = `1970-01-20T09:24:11.113+00:00\tThe first log event
40-
1970-01-20T09:24:11.114+00:00\tThe second log event
39+
const expectedText = `1970-01-20T09:24:11.113-08:00\tThe first log event
40+
1970-01-20T09:24:11.114-08:00\tThe second log event
4141
`
4242

4343
beforeEach(async function () {

src/test/cloudWatchLogs/document/textContent.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ The second log event
3535

3636
const { text, streamIdMap } = generateTextFromLogEvents(events, { timestamps: true })
3737

38-
const expectedText = `1970-01-20T09:24:11.113+00:00\tThe first log event
39-
1970-01-20T09:24:11.114+00:00\tThe second log event
38+
const expectedText = `1970-01-20T09:24:11.113-08:00\tThe first log event
39+
1970-01-20T09:24:11.114-08:00\tThe second log event
4040
`
4141
const expectedStreamIdMap = new Map([
4242
[0, 'stream1'],
@@ -58,8 +58,8 @@ The second log event
5858

5959
const { text, streamIdMap } = generateTextFromLogEvents(events, { timestamps: true })
6060

61-
const expectedText = `1970-01-20T09:24:11.113+00:00\tThe first log event
62-
1970-01-20T09:24:11.114+00:00\tThe second log event
61+
const expectedText = `1970-01-20T09:24:11.113-08:00\tThe first log event
62+
1970-01-20T09:24:11.114-08:00\tThe second log event
6363
${timestampSpaceEquivalent}\twith another line
6464
${timestampSpaceEquivalent}\tand another
6565
`

src/test/cloudWatchLogs/registry/logDataRegistry.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ describe('LogDataRegistry', async function () {
210210
it('matches CloudWatch insights timestamps', function () {
211211
const time = 1624201162222 // 2021-06-20 14:59:22.222 GMT+0
212212
const timestamp = formatDateTimestamp(true, new Date(time))
213-
assert.strictEqual(timestamp, '2021-06-20T14:59:22.222+00:00')
213+
assert.strictEqual(timestamp, '2021-06-20T14:59:22.222-07:00')
214214
})
215215
})
216216
})

0 commit comments

Comments
 (0)