Hello Golang-nuts,

*package main*

*import (*
* "fmt"*
* "time"*
*)*

*func main() {*
* t := time.Date(2009, time.December, 31, 23, 0, 0, 0, time.UTC)*
* fmt.Println(t)*
* fmt.Println(t.AddDate(0, -1, 0))*
*}*

https://play.golang.org/p/hZ7nhnkepK

The result is

2009-12-31 23:00:00 +0000 UTC
2009-12-01 23:00:00 +0000 UTC


I think it should be:

2009-12-31 23:00:00 +0000 UTC
2009-11-30 23:00:00 +0000 UTC


Documentation states that "AddDate normalizes its result in the same way that 
Date does, so, for example, adding one month to October 31 yields December 1, 
the normalized form for November 31."  This is makes sense when you work with 
time.Date() function, because hours and minutes involved, time zones, daylight 
savings etc. 

But it doesn't make any sense If you operate with days, months, years for 
analytical purposes. I think the normal practice ("Normalization") in this case 
would be to add exactly one month just like in other languages. Not one month 
and one day. SQL for example:


DECLARE @sp_Date DATETIME = '2009-12-31'

SELECT @sp_Date

SELECT DATEADD(mm , -1, @sp_Date)


2009-12-31 00:00:00.000

2009-11-30 00:00:00.000

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to