Hacker News new | past | comments | ask | show | jobs | submit login

Go seems to work as expected here:

    package main
    
    import (
       "fmt"
       "time"
    )
    
    func main() {
       dt := time.Unix(0, 0).UTC()
       fmt.Println(dt) // 1970-01-01 00:00:00 +0000 UTC
       fmt.Println(dt.Unix()) // 0
    }



Does Go also has a distinction between naive/timezone-aware times? If not don't see why would expect something else. This is an issue because the distinction exists. Note it isn't bad that it does. There're actually arguments in favor of it. It's bad that can freely mix them.


> Does Go also has a distinction between naive/timezone-aware times?

Why would you ever want or need that?


Suppose you want to run a routine after 12h. That is now is 7 PM and want it to run tomorrow at 7 AM. Like if simply print times you get:

  t1 = datetime.now()
  t2 = t1 + datetime.timedelta(days=0.5)
  print(str(t1)) # '2023-11-19 19:00:00.000000'
  print(str(t2)) # '2023-11-20 07:00:00.000000'


> That is now is 7 PM and want it to run tomorrow at 7 AM. Like if simply print times you get

is this English? also I am still not seeing a problem:

    package main
    
    import (
       "fmt"
       "time"
    )
    
    func main() {
       t1 := time.Now()
       t2 := t1.Add(12 * time.Hour)
       fmt.Println(t1) // 2023-11-19 15:14:16
       fmt.Println(t2) // 2023-11-20 03:14:16
    }


>is this English?

Ah, a grammar pedant. Haven't met one in a while.

>also I am still not seeing a problem

Try again setting your timezone to let's say NY and date at 2023-11-04. Oops.


> Ah, a grammar pedant. Haven't met one in a while.

"That is now is 7 PM"

"and want it to run tomorrow"

"Like if simply print"

none of these make sense

> Try again setting your timezone to let's say NY and date at 2023-11-04.

not sure what point youre trying to make, but youre failing:

    package main
    
    import (
       "fmt"
       "time"
    )
    
    func main() {
       t1 := time.Date(2023,11,4,7+12,0,0,0,time.FixedZone("EST", -5*3600))
       t2 := t1.Add(12 * time.Hour)
       fmt.Println(t1) // 2023-11-04 19:00:00 -0500 EST
       fmt.Println(t2) // 2023-11-05 07:00:00 -0500 EST
    }


>not sure what point youre trying to make, but youre failing

No wonder since you failed to correctly specify NY timezone in first place. Here's a trivia, it wasn't UTC-5 on that date.



It does, which is great. Note however that Go times can be either wall-time or (wall-time, monotonic time), which have different semantics and are both represented by the same type.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: