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 module: Week of Year is one day too late #23835

Closed
Brixy opened this issue Mar 1, 2025 · 3 comments
Closed

time module: Week of Year is one day too late #23835

Brixy opened this issue Mar 1, 2025 · 3 comments
Labels
Bug This tag is applied to issues which reports bugs. Modules: time Bugs/features, related to the `time` module. Unit: vlib Bugs/feature requests, that are related to the vlib.

Comments

@Brixy
Copy link

Brixy commented Mar 1, 2025

Describe the bug

Hi guys,

Maybe I found an error in the time module: The calculation of the "Week of Year" seems to be one day too late.

The 10th calendar week starts next Monday, 2025-03-03. Yet, ww for that date still shows week "09".

The 10th week falsely starts on Tuesday, 2025-03-04.

Date calculation is a "horrible" topic. So please bear with me if I have made a mistake ;-)

Reproduction Steps

import time

s := '2025-03-03 12:48:34'
t := time.parse(s)!
// `ww` should print `10`; instead it prints `09`
println(t.custom_format('YYYY-MM-DD ww (ddd)'))
// Apparently, a "Week of Year" starts on Tuesday (instead of Mondays)
// `ww` for 2025-03-04 is `10`
println(t.add_days(1).custom_format('YYYY-MM-DD ww (ddd)'))

Expected Behavior

ww should be "10" for both dates in the script.

Current Behavior

The first date (2025-03-03) prints 09 for ww.

Possible Solution

No response

Additional Information/Context

Shell programs handle this correctly. So I guess it's a V issue.

V version

0.4.9 f83af8a

Environment details (OS name and version, etc.)

Chimera Linux
Linux 6.12.16-0-generic
Wayland

(also tested on Void Linux)

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@Brixy Brixy added the Bug This tag is applied to issues which reports bugs. label Mar 1, 2025
Copy link

Connected to Huly®: V_0.6-22240

@felipensp felipensp added the Unit: vlib Bugs/feature requests, that are related to the vlib. label Mar 1, 2025
@jorgeluismireles
Copy link

Golang gives week=10 (as you said it should):

package main

import (
	"fmt"
	"time"
)

func main() {
	t := time.Date(2025, 3, 3, 12, 00, 00, 0, time.UTC)
	year, week := t.ISOWeek()
	fmt.Printf("year: %v\n", year)
	fmt.Printf("week: %d\n", week)
}
year: 2025
week: 10

@spytheman spytheman added the Modules: time Bugs/features, related to the `time` module. label Mar 1, 2025
@spytheman
Copy link
Member

spytheman commented Mar 2, 2025

With latest V, thanks to @kbkpbot's PR:

#0 10:10:53 ^ master ~/code/v>cat z.v
import time

s := '2025-03-03 12:48:34'
t := time.parse(s)!
// `ww` should print `10`; instead it prints `09`
println(t.custom_format('YYYY-MM-DD ww (ddd)'))
// Apparently, a "Week of Year" starts on Tuesday (instead of Mondays)
// `ww` for 2025-03-04 is `10`
println(t.add_days(1).custom_format('YYYY-MM-DD ww (ddd)'))
#0 10:11:00 ^ master ~/code/v>v run z.v
2025-03-03 10 (Mon)
2025-03-04 10 (Tue)
#0 10:11:03 ^ master ~/code/v>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Modules: time Bugs/features, related to the `time` module. Unit: vlib Bugs/feature requests, that are related to the vlib.
Projects
None yet
Development

No branches or pull requests

4 participants