|
| 1 | +# Calendar versioning reference |
| 2 | + |
| 3 | +## Calendar versioning codes |
| 4 | + |
| 5 | +The following table lists the available format codes for calendar versioning (CalVer) schemes. The codes can be used to define the version format in the `calver_format` configuration options. Formatting codes, surrounded by `{ }` can be combined to create a custom version format. For example, the format `YYYY.MM.DD` can be defined as `"{YYYY}.{MM}.{DD}"`. |
| 6 | + |
| 7 | +| Code | Example(s) | Comment | |
| 8 | +|--------|---------------------|-----------------------------------------------| |
| 9 | +| `YYYY` | 2000, 2001, …, 2099 | Full year | |
| 10 | +| `YY` | 0, 1, 2, …, 99 | Short year as integer | |
| 11 | +| `0Y` | 00, 01, 02, …, 99 | Short Year, zero-padded | |
| 12 | +| `MMM` | Jan, Feb, jan, fév | Month abbreviation, locale-based | |
| 13 | +| `MM` | 1, 2, …, 12 | Month as integer | |
| 14 | +| `0M` | 01, 02, …, 12 | Month, zero-padded | |
| 15 | +| `DD` | 1, 2, …, 31 | Day of month as integer | |
| 16 | +| `0D` | 01, 02, …, 31 | Day of month, zero-padded | |
| 17 | +| `JJJ` | 1, 2, 3, …, 366 | Day of year as integer | |
| 18 | +| `00J` | 001, 002, …, 366 | Day of year, zero-padded | |
| 19 | +| `Q` | 1, 2, 3, 4 | Quarter | |
| 20 | +| `WW` | 0, 1, 2, …, 53 | Week number, Monday is first day | |
| 21 | +| `0W` | 00, 01, 02, …, 53 | Week number, Monday is first day, zero-padded | |
| 22 | +| `UU` | 0, 1, 2, …, 53 | Week number, Sunday is first day | |
| 23 | +| `0U` | 00, 01, 02, …, 53 | Week number, Sunday is first day, zero-padded | |
| 24 | +| `VV` | 1, 2, …, 53 | ISO 8601 week number as integer | |
| 25 | +| `0V` | 01, 02, …, 53 | ISO 8601 week number, zero-padded | |
| 26 | +| `GGGG` | 2000, 2001, …, 2099 | ISO 8601 week-based year | |
| 27 | +| `GG` | 0, 1, 2, …, 99 | ISO 8601 short week-based year as integer | |
| 28 | +| `0G` | 01, 02, …, 99 | ISO 8601 short week-based year, zero-padded | |
| 29 | + |
| 30 | +```toml title="Example configuration" |
| 31 | +[tool.bumpversion.parts.release] |
| 32 | +calver_format = "{YYYY}.{MM}.{DD}" |
| 33 | +``` |
| 34 | + |
| 35 | + |
| 36 | +## Parsing CalVer versions |
| 37 | + |
| 38 | +Using the following chart, we can set up the version parsing: |
| 39 | + |
| 40 | +| Code | Regex | |
| 41 | +|--------|-------------------------------------------------------------------| |
| 42 | +| `YYYY` | `(?:[1-9][0-9]{3})` | |
| 43 | +| `YY` | `(?:[1-9][0-9]?)` | |
| 44 | +| `0Y` | `(?:[0-9]{2})` | |
| 45 | +| `MMM` | See below | |
| 46 | +| `MM` | `(?:1[0-2]\|[1-9])` | |
| 47 | +| `0M` | `(?:1[0-2]\|0[1-9])` | |
| 48 | +| `DD` | `(?:3[0-1]\|[1-2][0-9]\|[1-9])` | |
| 49 | +| `0D` | `(?:3[0-1]\|[1-2][0-9]\|0[1-9])` | |
| 50 | +| `JJJ` | `(?:36[0-6]\|3[0-5][0-9]\|[1-2][0-9][0-9]\|[1-9][0-9]\|[1-9])` | |
| 51 | +| `00J` | `(?:36[0-6]\|3[0-5][0-9]\|[1-2][0-9][0-9]\|0[1-9][0-9]\|00[1-9])` | |
| 52 | +| `Q` | `(?:[1-4])` | |
| 53 | +| `WW` | `(?:5[0-3]\|[1-4][0-9]\|[0-9])` | |
| 54 | +| `0W` | `(?:5[0-3]\|[0-4][0-9])` | |
| 55 | +| `UU` | `(?:5[0-3]\|[1-4][0-9]\|[0-9])` | |
| 56 | +| `0U` | `(?:5[0-3]\|[0-4][0-9])` | |
| 57 | +| `VV` | `(?:5[0-3]\|[1-4][0-9]\|[1-9])` | |
| 58 | +| `0V` | `(?:5[0-3]\|[1-4][0-9]\|0[1-9])` | |
| 59 | +| `GGGG` | `(?:[1-9][0-9]{3})` | |
| 60 | +| `GG` | `(?:[0-9][0-9]?)` | |
| 61 | +| `0G` | `(?:[0-9]{2})` | |
| 62 | + |
| 63 | +!!! Note "Month abbreviations" |
| 64 | + |
| 65 | + The month abbreviation is locale-based. Here are some examples: |
| 66 | + |
| 67 | + `(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)` for English |
| 68 | + |
| 69 | + `(?:jan|fév|mar|avr|mai|jui|jui|aoû|sep|oct|nov|déc)` for French |
| 70 | + |
| 71 | +You can use these regular expressions to parse CalVer versions in your project. For example, the following `parse` configuration can be used to parse a version string in the format `YYYY.MM.DD` as the `release` part of the version string: |
| 72 | + |
| 73 | +```toml |
| 74 | +[tool.bumpversion] |
| 75 | +parse = """(?x) # Verbose mode |
| 76 | + (?P<release> |
| 77 | + (?:[1-9][0-9]{3})\\. # YYYY. |
| 78 | + (?:1[0-2]|[1-9])\\. # MM. |
| 79 | + (?:3[0-1]|[1-2][0-9]|[1-9]) # DD |
| 80 | + ) |
| 81 | +""" |
| 82 | +``` |
| 83 | + |
| 84 | +## CalVer incrementing logic |
| 85 | + |
| 86 | +- CalVer version components are marked as `always_increment` by default. |
| 87 | +- When bumping a version, you specify which component to increment. It is called the target component. |
| 88 | +- When bumping a version, the components marked as `always_increment` are incremented first. |
| 89 | +- If an `always_increment` component's value changed, its dependent components are marked for reset to their default values. |
| 90 | +- If the target component is in the set of components marked for reset, the target component is reset to its default value. |
| 91 | +- If the target component is not in the set of components marked for reset, the target component is incremented and its dependent components are reset to their default values. |
0 commit comments