Zero pad the month number in the versioning scheme?

I’m not sure of the best place for this but I’ve just noticed from the repo blog post for the next version that the new versioning system uses the “short month” form rather than “zero-padded month” for calendar versioning.

I’m a big fan of calendar versioning but the short form can lead to issues when sorting alphabetically as is often done for file lists. For example, folders for versions this year could end up as:

  • 2021.1/
  • 2021.10/
  • 2021.11/
  • 2021.12/
  • 2021.2/
  • 2021.3/

Might be a bit late for this now but would it be better to use the zero-padded form similar to Ubuntu?

  • 2021.01/
  • 2021.01.1/
  • 2021.02/
  • 2021.03/
  • 2021.09/
  • 2021.10/
  • 2021.11/
  • 2021.12/
  • 2022.01/

What would be the use case that requires such sorting?

I can’t remember the specific use case I had or if I had one. It’s just a convenience thing more than anything which I default to whenever using calendar versioning.

For example, if someone has downloaded the latest release in October, it will appear after the September release in their downloads folder (if sorting alphabetically). Any files someone has in github prefixed with the version number will display in chronological order rather than jumping up every October, etc.

The biggest advantage comes in programatically working with the version numbers though. Here’s a python example of grabbing the latest version number in the two formats:

versions = ['2022.1','2022.2','2022.3','2022.4','2022.5','2022.6','2022.7','2022.8','2022.9','2022.10','2022.11','2022.12']
versionsPadded = ['2022.01','2022.02','2022.03','2022.04','2022.05','2022.06','2022.07','2022.08','2022.09','2022.10','2022.11','2022.12']

# Attempting to sort the list and grab the last element results in the wrong value
latestVersion = sorted(versions)[-1]
print(latestVersion) # 2022.9 Wrong!

# Instead you have to split it into parts, sort numerically and recombine
# This only covers year.month and not patch.
# There may be more efficient ways to do this which allows for more parts.
latestVersionYear = sorted(versions)[-1].split('.')[0]
monthReleasesForLatestYear = [int(v.split('.')[1]) for v in versions if v.startswith(f'{latestVersionYear}.')]
latestMonthReleaseForYear = sorted(monthReleasesForLatestYear)[-1]
latestRelease = f'{latestVersionYear}.{latestMonthReleaseForYear}'
print(latestRelease) # 2022.12 Correct!

# With padded version numbers, sorting alphabetically is sufficient
latestVersion = sorted(versionsPadded)[-1]
print(latestVersion) # 2022.12 Correct!

From the other side of building up the version number, it only requires one extra line:

buildYear = 2022
buildMonth = 5

# Current format
print(f'{buildYear}.{buildMonth}') # 2022.5

# Padded format
paddedBuildMonth = f'0{buildMonth}'[-2:]
print(f'{buildYear}.{paddedBuildMonth}') # 2022.05

Not tried this but I expect a comparison would also work with zero-padded:

if myVersion < currentVersion:
   # Do something...

To be clear, I only see this as a nice to have but that’s just my opinion and not necessarily those of the people voting. I’m not sure how many places sorting like this would happen so it may be more effort to use zero-padded numbers than I realise (although the parsing as above should work both with and without zero-padding). If it’s going to take much effort, I would much rather the focus stay on some of those great features you bring us each month!