Skip to content

time: add week_of_year() - #23838

Merged
spytheman merged 5 commits into
vlang:masterfrom
kbkpbot:time_week_of_year
Mar 2, 2025
Merged

spytheman merged 5 commits into
vlang:masterfrom
kbkpbot:time_week_of_year

Conversation

@kbkpbot

@kbkpbot kbkpbot commented Mar 1, 2025

Copy link
Copy Markdown
Contributor

Follow ISO 8601 standard.
Fix issue #23835

@huly-for-github

Copy link
Copy Markdown

Connected to Huly®: V_0.6-22243

@spytheman

Copy link
Copy Markdown
Contributor

I tried the following program:

import time

mut now := time.now()
for d in 1..315 {
    println('>> ${now} | d: ${d:03} | .day_of_week(): ${now.day_of_week()} |  .strftime_V: ${now.strftime('%V')} | .week_of_year: ${now.week_of_year():02}')
    now = now.add_days(1)
}

which printed:
image

Is there a reason for the difference from the .strftime('%V') result, around the new year?

>> 2025-12-28 23:57:53 | d: 303 | .day_of_week(): 7 |  .strftime_V: 52 | .week_of_year: 52
>> 2025-12-29 23:57:53 | d: 304 | .day_of_week(): 1 |  .strftime_V: 01 | .week_of_year: 53
>> 2025-12-30 23:57:53 | d: 305 | .day_of_week(): 2 |  .strftime_V: 01 | .week_of_year: 53
>> 2025-12-31 23:57:53 | d: 306 | .day_of_week(): 3 |  .strftime_V: 01 | .week_of_year: 53
>> 2026-01-01 23:57:53 | d: 307 | .day_of_week(): 4 |  .strftime_V: 01 | .week_of_year: 01

@spytheman

Copy link
Copy Markdown
Contributor

Excellent work.
Thanks for the new function 🙇🏻‍♂️ .

I've tried to implement it in the past for .github/workflows/show_manual_release_cmd.vsh, but could not figure out the full details, so I settled on using .strftime() instead.

@spytheman
spytheman merged commit 57a45bc into vlang:master Mar 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants