LastUpdated v1.9_2025-06-08
Posted by rphyrin on 8 June 2025 in English. Last updated on 10 June 2025.Recently, I needed to open my OpenStreetMap profile—just to right-click and save my own profile picture for use on another platform.
Thanks to the newly redesigned OSM profile layout, I was greeted by a few new statistics—one of which showed how many comments my last diary post had received. While I was busy grabbing my avatar, I couldn’t help but notice that my recent diary post had garnered quite a bit of discussion.
To my surprise, at least two commenters pointed out the same thing : they suggested it would be more intuitive if the value reflected actual months, rather than “something that roughly represents the progress of the year in base-10.”
That got me thinking—how hard would it be to convert that base-10 year-progress value into something closer to a conventional month (base-12)?
Step 1: Extract the Year
To compute the year from an OSM timestamp (Unix time), we start by offsetting it from a known reference point—specifically, the Unix timestamp for the start of the year 2000.
(osm_timestamp - 946692127) / 31556952
- 946692127 is the Unix timestamp for Sat Jan 01 2000 02:02:07 GMT+0000. This value was arbitrarily chosen by me (high accuracy isn’t necessary; I just needed a reference point roughly around the year 2000).
- 31556952 is the average number of seconds in a year (365.2425 days).
This gives us a floating-point number: the integer part is the year offset from 2000.
To extract the integer part (representing the year), we can substring the first 2 character:
substring(divided_by(osm_timestamp - 946692127, 31556952), 0, 2)
Oh wait!
While writing this post, I stumbled upon a small but interesting bug from the initial release.
Originally, the code extracted the first three characters of the computed year value. This worked fine for double-digit years like 2010 and beyond—10.5 would yield “10.”, which was sufficient for identifying the year and using the decimal as a makeshift separator between year and month.