Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R2 Bindings do not allow dates past 2189 #1687

Open
Manouchehri opened this issue Feb 18, 2024 · 0 comments
Open

R2 Bindings do not allow dates past 2189 #1687

Manouchehri opened this issue Feb 18, 2024 · 0 comments

Comments

@Manouchehri
Copy link

Presumably due to toKjDate, the R2 bindings are unable to use dates past Thu, 31 Dec 2189 23:59:59 GMT (aka new Date("2189-12-31T23:59:59.999Z")).

kj::Date toKjDate(double millis) {
JSG_REQUIRE(isFinite(millis),
TypeError,
"The value cannot be converted because it is not a valid Date.");
// JS Date uses milliseconds stored as a double-precision float to represent times
// KJ uses nanoseconds stored as an int64_t, which is significantly smaller but larger
// than my lifetime.
//
// For most use-cases, throwing when we encounter a date outside of KJ's supported range is OK.
// API's that need to support time-travelers or historians may need to consider using the
// V8 Date type directly.
constexpr double millisToNanos = kj::MILLISECONDS / kj::NANOSECONDS;
double nanos = millis * millisToNanos;
JSG_REQUIRE(nanos < int64_t(kj::maxValue), TypeError, "This API doesn't support dates after 2189.");

This isn't ideal, as some people (like me 😅 ), use Fri, 31 Dec 9999 23:59:59 GMT as their default "never expire" date for S3 bucket objects.

If R2 only uses milliseconds internally, shouldn't the Workers R2 bindings allow up to year 9999? (Based on the R2Object responses I see from .put, it looks like R2 only uses milliseconds, not nanoseconds. I could be wrong though.)

{
  "customMetadata": {},
  "httpMetadata": {
    "contentType": "application/pdf",
    "contentDisposition": "inline; filename=\"f9ea747b68e91d1490180937d5ac2255.pdf\"",
    "cacheControl": "public, immutable, no-transform, max-age=31536000, s-maxage=31536000",
    "cacheExpiry": "2189-12-31T23:59:59.999Z"
  },
  "uploaded": "2024-02-07T19:40:24.552Z",
  "checksums": {
    "md5": "f9ea747b68e91d1490180937d5ac2255"
  },
  "httpEtag": "\"f9ea747b68e91d1490180937d5ac2255\"",
  "etag": "f9ea747b68e91d1490180937d5ac2255",
  "size": 3688121,
  "version": "7e727aea0ee83562cb20d56589912332",
  "key": "27f01495cb0ea9d387a37001a59def73ae0750575681cbbb6afbf590225b64c2"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant