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

AddDate() not works correctly #25

Open
MohammadGhodsian opened this issue Jun 11, 2023 · 0 comments
Open

AddDate() not works correctly #25

MohammadGhodsian opened this issue Jun 11, 2023 · 0 comments

Comments

@MohammadGhodsian
Copy link

While appreciating the project, AddDate() not works correctly. As a sample, today is 2023-06-11 OR 1402/03/21

By using this sample (the dates of the days of the future years):

func main() {
	pt := pTime.Now()
	utility.UFileDelete("dates.txt")
	for i := 0; i < 3650; i++ {
		pd := pt.AddDate(0, 0, i)
		utility.UFileAppend("dates.txt", strconv.Itoa(i)+" : "+pd.Format("yyyy/MM/dd  E  MMMMM  D/RD  w/rw")+"\n                                             "+pd.Time().String()+"\n", false)
	}
}

The output is (end of 1402):

image

Today + 286 -> 1402/12/28 2024-03-18

Today + 287 -> 1402/12/29 2024-03-19
Today + 288 -> 1402/12/29 2024-03-19
Today + 289 -> 1403/01/01 2024-03-20
Today + 290 -> 1403/01/01 2024-03-20

Today + 291 -> 1403/01/02 2024-03-21


But with updating the code as below by adding the days to standard time package:

func main() {
	t := 10 * 365
	now := time.Now()
	utility.UFileDelete("dates.txt")
	for i := 0; i < t; i++ {
		p := now.AddDate(0, 0, i)
		pt := pTime.Unix(p.Unix(), 0)
		utility.UFileAppend("dates.txt", strconv.Itoa(i)+" : "+pt.Format("yyyy/MM/dd  E  MMMMM  D/RD  w/rw")+"\n                                                  "+pt.Time().Format(time.UnixDate)+"\n", false)
	}
}
image

...
Today + 281 -> 1402/12/28 2024-03-18
Today + 282 -> 1402/12/29 2024-03-19
Today + 283 -> 1403/01/01 2024-03-20
Today + 284 -> 1403/01/02 2024-03-21
...
Today + 286 -> 1403/01/04 2024-03-23
Today + 287 -> 1403/01/05 2024-03-24
Today + 288 -> 1403/01/06 2024-03-25
Today + 289 -> 1403/01/07 2024-03-26
Today + 290 -> 1403/01/08 2024-03-27
...

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

No branches or pull requests

1 participant