Skip to content

Commit

Permalink
fix(smithy-client): rfc-7231 date-time value (#3814)
Browse files Browse the repository at this point in the history
* fix(smithy-client): rfc-7231 date-time value
  • Loading branch information
dustin-lennon authored Jul 25, 2022
1 parent 32022f9 commit f52a985
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
36 changes: 36 additions & 0 deletions packages/smithy-client/src/date-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ describe("parseRfc7231DateTime", () => {
expect(parseRfc7231DateTime(value)).toEqual(new Date(Date.UTC(1994, 10, 6, 8, 49, 37, 520)));
});
});
describe("with fractional seconds - single digit hour", () => {
it.each([
["imf-fixdate", "Sun, 06 Nov 1994 8:49:37.52 GMT"],
["rfc-850", "Sunday, 06-Nov-94 8:49:37.52 GMT"],
["asctime", "Sun Nov 6 8:49:37.52 1994"],
])("in format %s", (_, value) => {
expect(parseRfc7231DateTime(value)).toEqual(new Date(Date.UTC(1994, 10, 6, 8, 49, 37, 520)));
});
});
describe("without fractional seconds", () => {
it.each([
["imf-fixdate", "Sun, 06 Nov 1994 08:49:37 GMT"],
Expand All @@ -72,6 +81,15 @@ describe("parseRfc7231DateTime", () => {
expect(parseRfc7231DateTime(value)).toEqual(new Date(Date.UTC(1994, 10, 6, 8, 49, 37, 0)));
});
});
describe("without fractional seconds - single digit hour", () => {
it.each([
["imf-fixdate", "Sun, 06 Nov 1994 8:49:37 GMT"],
["rfc-850", "Sunday, 06-Nov-94 8:49:37 GMT"],
["asctime", "Sun Nov 6 8:49:37 1994"],
])("in format %s", (_, value) => {
expect(parseRfc7231DateTime(value)).toEqual(new Date(Date.UTC(1994, 10, 6, 8, 49, 37, 0)));
});
});
describe("with leap seconds", () => {
it.each([
["imf-fixdate", "Mon, 31 Dec 1990 15:59:60 GMT"],
Expand All @@ -81,6 +99,15 @@ describe("parseRfc7231DateTime", () => {
expect(parseRfc7231DateTime(value)).toEqual(new Date(Date.UTC(1990, 11, 31, 15, 59, 60, 0)));
});
});
describe("with leap seconds - single digit hour", () => {
it.each([
["imf-fixdate", "Mon, 31 Dec 1990 8:59:60 GMT"],
["rfc-850", "Monday, 31-Dec-90 8:59:60 GMT"],
["asctime", "Mon Dec 31 8:59:60 1990"],
])("in format %s", (_, value) => {
expect(parseRfc7231DateTime(value)).toEqual(new Date(Date.UTC(1990, 11, 31, 8, 59, 60, 0)));
});
});
describe("with leap days", () => {
it.each([
["imf-fixdate", "Sun, 29 Feb 2004 15:59:59 GMT"],
Expand All @@ -90,6 +117,15 @@ describe("parseRfc7231DateTime", () => {
expect(parseRfc7231DateTime(value)).toEqual(new Date(Date.UTC(2004, 1, 29, 15, 59, 59, 0)));
});
});
describe("with leap days - single digit hour", () => {
it.each([
["imf-fixdate", "Sun, 29 Feb 2004 8:59:59 GMT"],
["rfc-850", "Sunday, 29-Feb-04 8:59:59 GMT"],
["asctime", "Sun Feb 29 8:59:59 2004"],
])("in format %s", (_, value) => {
expect(parseRfc7231DateTime(value)).toEqual(new Date(Date.UTC(2004, 1, 29, 8, 59, 59, 0)));
});
});
describe("with leading zeroes", () => {
it.each([
["imf-fixdate", "Sun, 06 Nov 0004 08:09:07.02 GMT", 4],
Expand Down
6 changes: 3 additions & 3 deletions packages/smithy-client/src/date-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ export const parseRfc3339DateTime = (value: unknown): Date | undefined => {
};

const IMF_FIXDATE = new RegExp(
/^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d{2}) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d{2}):(\d{2}):(\d{2})(?:\.(\d+))? GMT$/
/^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d{2}) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d{1,2}):(\d{2}):(\d{2})(?:\.(\d+))? GMT$/
);
const RFC_850_DATE = new RegExp(
/^(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (\d{2})-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d{2}) (\d{2}):(\d{2}):(\d{2})(?:\.(\d+))? GMT$/
/^(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (\d{2})-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d{2}) (\d{1,2}):(\d{2}):(\d{2})(?:\.(\d+))? GMT$/
);
const ASC_TIME = new RegExp(
/^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( [1-9]|\d{2}) (\d{2}):(\d{2}):(\d{2})(?:\.(\d+))? (\d{4})$/
/^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( [1-9]|\d{2}) (\d{1,2}):(\d{2}):(\d{2})(?:\.(\d+))? (\d{4})$/
);

/**
Expand Down

0 comments on commit f52a985

Please sign in to comment.