HACKER Q&A
📣 MollyRealized

Library that maps clock times to human terms ("early morning", etc.)?


I am wondering if people have already done the work on what I'm about to describe. I'm going to try to define what's in my mind by explaining the working circumstance. The humidity part of the below, however, is solved - I'm just trying to explain the kind of substitution I'd like.

For me, temperature doesn't mean as much as stickiness. So I worked out a script that takes the dew point and maps it against a humidity comfort index. I have both the next 24 hours, and the next six days.

Right now, my script reads out the next 24 hours like this:

"From 5-10 AM, it will be pleasant (0). At 11:57 AM, it will be sticky (1). At 12:57 PM, it will be pleasant (0). From 1-10 PM, it will be refreshing (-1). At 11:57 PM, it will be pleasant (0). From 12-4 AM, it will be sticky (1)."

What I'm wondering - before I try to reinvent the wheel - is if there is basically a generalized library or reference that lets you define things using more ambiguous, human terms. I imagine it would have to define not only morning, afternoon, and evening, but also have "early", "mid", and "late" adjectives, as well as overnight.

For example, if this library existed, I could implement it into the script and then it might say:

"This morning, it will be pleasant (0). At noon, it will be sticky (1). The afternoon and night, it will be refreshing (-1). Overnight, it will be sticky (1)."


  👤 austin-cheney Accepted Answer ✓
That should be extremely simple for anyone to write themselves.

👤 markussss
There are probably several libraries that offer this functionality, the question is just what your other requirements are. It is also built into most modern web browsers, just check out the MDN for Intl.DateTimeFormat with the dayPeriod option [1].

[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...