Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.7 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
69f35a5bb823ed620fcb7cb9 Challenge 280: Mongo ID Date 28 challenge-280

--description--

Given a MongoDB ID string, return its creation time as an ISO 8601 string.

  • A MongoDB ID is a 24-character hex string. The first 8 characters represent a Unix timestamp (in seconds) encoded as a base-16 integer.

For example, "6a094b50bcf86cd799439011" has a timestamp of "6a094b50" in hex, which is 1778994000 in decimal, representing a creation time of "2026-05-17T05:00:00.000Z".

--hints--

mongoIdToDate("6a094b50bcf86cd799439011") should return "2026-05-17T05:00:00.000Z".

assert.equal(mongoIdToDate("6a094b50bcf86cd799439011"), "2026-05-17T05:00:00.000Z");

mongoIdToDate("695344eb1f4a4c1123042128") should return "2025-12-30T03:20:11.000Z".

assert.equal(mongoIdToDate("695344eb1f4a4c1123042128"), "2025-12-30T03:20:11.000Z");

mongoIdToDate("386da62df34123ac54617e56") should return "2000-01-01T07:01:01.000Z".

assert.equal(mongoIdToDate("386da62df34123ac54617e56"), "2000-01-01T07:01:01.000Z");

mongoIdToDate("69f571c3d7711807afd3dd55") should return "2026-05-02T03:38:43.000Z".

assert.equal(mongoIdToDate("69f571c3d7711807afd3dd55"), "2026-05-02T03:38:43.000Z");

mongoIdToDate("68adce01c0e1144d0a90295a") should return "2025-08-26T15:08:49.000Z".

assert.equal(mongoIdToDate("68adce01c0e1144d0a90295a"), "2025-08-26T15:08:49.000Z");

--seed--

--seed-contents--

function mongoIdToDate(id) {

  return id;
}

--solutions--

function mongoIdToDate(id) {
  const timestamp = parseInt(id.slice(0, 8), 16);
  return new Date(timestamp * 1000).toISOString();
}