Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time: add week_of_year() #23838

Merged
merged 5 commits into from
Mar 2, 2025
Merged

time: add week_of_year() #23838

merged 5 commits into from
Mar 2, 2025

Conversation

kbkpbot
Copy link
Contributor

@kbkpbot kbkpbot commented Mar 1, 2025

Follow ISO 8601 standard.
Fix issue #23835

Copy link

Connected to Huly®: V_0.6-22243

@spytheman
Copy link
Member

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
Member

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
62 checks passed
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