Skip to content

Instantly share code, notes, and snippets.

@mbbx6spp
Last active October 14, 2024 14:16
Show Gist options
  • Save mbbx6spp/aa6bde911b889e8ef5672a89c130d227 to your computer and use it in GitHub Desktop.
Save mbbx6spp/aa6bde911b889e8ef5672a89c130d227 to your computer and use it in GitHub Desktop.
Using the NPM edts library to show how you might use approximate or uncertain dates in EDTF format with a supporting library contrasting it with an interval in EDTF form. Answering this tweet: https://x.com/alllexist/status/1845810486769508728
import edtf, { Date, Interval } from 'npm:edtf@4.6.0';
const approxStartDate = edtf('2024-10-14~');
const uncertainDate = edtf('2024-10-14?');
const interval = edtf('2024-10-11/2024-10-16');
console.table([
approxStartDate.edtf,
approxStartDate.min,
approxStartDate.max,
approxStartDate.approximate,
approxStartDate.uncertain,
approxStartDate.covers(approxStartDate),
approxStartDate.covers(uncertainDate),
approxStartDate.covers(approxStartDate.next()),
])
console.table([
uncertainDate.edtf,
uncertainDate.min,
uncertainDate.max,
uncertainDate.approximate,
uncertainDate.uncertain,
uncertainDate.covers(uncertainDate),
uncertainDate.covers(approxStartDate),
uncertainDate.covers(uncertainDate.next()),
])
console.table([
interval.edtf,
interval.min,
interval.max,
interval.approximate,
interval.uncertain,
interval.covers(uncertainDate),
interval.covers(approxStartDate),
])
┌───────┬───────┬───────────────┐
│ (idx) │ value │ Values │
├───────┼───────┼───────────────┤
│ 0 │ │ "2024-10-14~" │
│ 1 │ │ 1728864000000 │
│ 2 │ │ 1728950399999 │
│ 3 │ 255 │ │
│ 4 │ 0 │ │
│ 5 │ │ true │
│ 6 │ │ true │
│ 7 │ │ false │
└───────┴───────┴───────────────┘
┌───────┬───────┬───────────────┐
│ (idx) │ value │ Values │
├───────┼───────┼───────────────┤
│ 0 │ │ "2024-10-14?" │
│ 1 │ │ 1728864000000 │
│ 2 │ │ 1728950399999 │
│ 3 │ 0 │ │
│ 4 │ 255 │ │
│ 5 │ │ true │
│ 6 │ │ true │
│ 7 │ │ false │
└───────┴───────┴───────────────┘
┌───────┬─────────────────────────┐
│ (idx) │ Values │
├───────┼─────────────────────────┤
│ 0 │ "2024-10-11/2024-10-16" │
│ 1 │ 1728604800000 │
│ 2 │ 1729123199999 │
│ 3 │ undefined │
│ 4 │ undefined │
│ 5 │ true │
│ 6 │ true │
└───────┴─────────────────────────┘
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment