date
¶
compute_time_span_string(start_date, end_date, *, locale, current_date, time_span_template)
¶
Calculate and format duration between dates with localized units.
Why
CV readers need quick understanding of experience length. Automatic calculation shows "2 years 3 months" or "1 year" based on date precision, with proper singular/plural forms per locale.
Example
Parameters:
-
start_date(str | int) –Start date as integer year or ISO date string.
-
end_date(str | int) –End date as integer year, ISO date string, or "present".
-
locale(Locale) –Locale providing year/month singular/plural forms.
-
current_date(date) –Reference date for "present" calculation.
-
time_span_template(str) –Template for formatting duration output.
Returns:
-
str–Formatted time span string with years and months.
Source code in src/rendercv/renderer/templater/date.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
date_object_to_string(date, *, locale, single_date_template)
¶
Convert date object to localized string using template placeholders.
Why
Date display varies by locale and user preference. Template-based formatting allows MONTH_ABBREVIATION YEAR or MONTH_NAME, YEAR without hardcoding formats for each language.
Example
Parameters:
-
date(date) –Date to format.
-
locale(Locale) –Locale providing month names and abbreviations.
-
single_date_template(str) –Template with date placeholders.
Returns:
-
str–Formatted date string with placeholders substituted.
Source code in src/rendercv/renderer/templater/date.py
format_date_range(start_date, end_date, *, locale, single_date_template, date_range_template)
¶
Format date range with localized start and end dates.
Why
CV entries use date ranges for employment and education. Users provide dates as year-only integers, YYYY-MM strings, YYYY-MM-DD strings, or "present". Unified formatting handles all input types consistently.
Example
Parameters:
-
start_date(str | int) –Start date as integer year or ISO date string.
-
end_date(str | int) –End date as integer year, ISO date string, or "present".
-
locale(Locale) –Locale providing month names and present translation.
-
single_date_template(str) –Template for formatting individual dates.
-
date_range_template(str) –Template combining start and end dates.
Returns:
-
str–Formatted date range string.
Source code in src/rendercv/renderer/templater/date.py
format_single_date(date, *, locale, single_date_template)
¶
Format single date with locale-aware template or pass through custom strings.
Why
Publications and certifications use single dates rather than ranges. Custom date strings like "Spring 2024" need preservation while standard dates require localized formatting.
Example
# Standard date formatting
result = format_single_date(
"2024-03", locale=english_locale, single_date_template="MONTH_NAME YEAR"
)
# Returns: "March 2024"
# Custom string pass-through
result = format_single_date(
"Spring 2024", locale=english_locale, single_date_template="MONTH_NAME YEAR"
)
# Returns: "Spring 2024"
Parameters:
-
date(str | int) –Date as integer year, ISO date string, "present", or custom text.
-
locale(Locale) –Locale providing present translation.
-
single_date_template(str) –Template for formatting standard dates.
Returns:
-
str–Formatted date string or original custom text.