Skip to content

AddDate() not works correctly #25

@MohammadGhodsian

Description

@MohammadGhodsian

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
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions