gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmain0f6d1592Merge branch 'f18b-shell-session' into mainIdentmain/lib/usedin-helpers.hl

1.3 KB

  1. // lib/usedin-helpers.hl — what lib/usedin.hl shows (ident#26): a day as "Oct 22", a past time as "4 min ago". No table
  2. // access. Statics only.
  3. import { timestamp } from 'hl:time'
  4. static months = ['Jan' 'Feb' 'Mar' 'Apr' 'May' 'Jun' 'Jul' 'Aug' 'Sep' 'Oct' 'Nov' 'Dec']
  5. // "Oct 22" (UTC; hl:time knows no zones, hybriel #11) — with the year when it is not the current one
  6. static dayText = (ms, nowMs) => {
  7. if (ms == null) { return '' }
  8. t = timestamp(ms)
  9. m = toNumber(t.slice(5, 7))
  10. d = toNumber(t.slice(8, 10))
  11. y = t.slice(0, 4)
  12. let out = months[m - 1] + ' ' + d
  13. if (y != timestamp(nowMs).slice(0, 4)) { out = out + ' ' + y }
  14. return out
  15. }
  16. // no floor without hl:math: the whole part of a positive number
  17. static whole = (x) => { return x - x % 1 }
  18. // "just now" · "4 min ago" · "2 h ago" · "3 d ago"
  19. static agoText = (ms, nowMs) => {
  20. if (ms == null) { return '' }
  21. secs = (nowMs - ms) / 1000
  22. if (secs < 60) { return 'just now' }
  23. m = whole(secs / 60)
  24. if (m < 60) { return m + ' min ago' }
  25. h = whole(m / 60)
  26. if (h < 24) { return h + ' h ago' }
  27. return whole(h / 24) + ' d ago'
  28. }
  29. // the row's second line: "since Oct 22 · last use 4 min ago" (a connection older than the recording: "last use not recorded")
  30. static usedLine = (since, lastLogin, nowMs) => {
  31. last = lastLogin == null ? 'last use not recorded' : 'last use ' + agoText(lastLogin, nowMs)
  32. return 'since ' + dayText(since, nowMs) + ' · ' + last
  33. }

Branches

Latest commits

  • 0f6d1592Merge branch 'f18b-shell-session' into mainIdent
  • 19868218|||PR ident#39 shell reads its session member instead of a cross-file emitmre
  • 5d1b3fedMerge branch 'v61-day61' into mainIdent
  • 83faeb15|||PR ident: vendor Hybriel day61mre
  • b2572b34Merge branch 'v59-day59' into mainIdent
  • 67cf016d|||PR ident: vendor Hybriel day59mre
  • 600c043dMerge branch 'v58-day58' into mainIdent
  • 365f8c80|||PR ident: vendor Hybriel day58mre
  • 585126e5Merge branch 'f16-setf' into mainIdent
  • 953bf03a|||PR ident setF mirror dropped (hybriel#370)mre
  • a1419d9cMerge branch 'f15-navigate' into mainIdent
  • 3b3e451f|||PR ident#36 navigate to the app instead of location.assignmre
  • e36f4516Merge branch 'f14-online' into mainIdent
  • 2c5eac91|||PR ident#38 online state without probe timermre
  • bf1980f2Merge branch 'v56-day56' into mainIdent
  • 62ae0adf|||PR ident: vendor Hybriel day56mre
  • 0d18abc4Merge branch 'f13-avatar' into mainIdent
  • 2a99730a|||PR ident#37 avatar in hlmre
  • fa4ed25bMerge branch 'f11-upsert' into mainIdent
  • 8f3d9bc9|||PR ident#42 keyed upsert and removemre