Evergreen posts 0 ▲ Ned Batchelder's blog 2 hours ago · Tech · hide · 0 comments Because I’ve been writing this blog for so long, I often share links to very old posts. Three years ago, I added a feature: if the post is more than five years old, there’s a message next to the dateline indicating the age.The age descriptions adjust automatically when the post is rendered. I had fun implementing the human-style age descriptions: “nearly 12 years”, “more than seven years”, “exactly nine years”, etc:NUMBER_NAMES = dict(enumerate( "zero one two three four five six seven eight nine ten".split() )) def years_age(age): years, frac = divmod(age.days / 365.25, 1) years = int(years) if frac < 1/365: modifier = "exactly " elif frac < 2/12: modifier = "" elif frac < 4/12: modifier = "more than " elif frac < 8/12: modifier = "over " elif frac < 9/12: modifier = "close to " years += 1 elif frac < 10/12: modifier = "almost " years += 1 elif frac < 11/12: modifier = "nearly " years += 1 elif frac < 364/365: modifier = "" years += 1 else: modifier = "exactly " years += 1 years =… No comments yet. Log in to reply on the Fediverse. Comments will appear here.