Something like python timedelta in golang
Question: I want to get a datetime, counting weeks from a date, days from a week and
seconds from 00:00 time.

With Python I can use this:

    
    
    BASE_TIME = datetime.datetime(1980,1,6,0,0)
    tdelta = datetime.timedelta(weeks = 1722,
                                days = 1,
                                seconds = 66355)
    mydate = BASE_DATE + tdelta
    

I'm trying to get it with Go, but I have some problems to reach it:

    
    
    package main
    
    import (
        "fmt"
        "time"
    )
    
    var base = time.Date(1980, 1, 6, 0, 0, 0, 0, time.UTC)
    
    func main() {
        weeks := 1722
        days := 1
        seconds := 66355
        weeksToSecs := 7 * 24 * 60 * 60
        daysToSecs := 24 * 60 * 60
        totalSecs := (weeks * weeksToSecs) + (days * daysToSecs) + seconds
        nanosecs := int64(totalSecs) * 1000000000
    
        //delta := time.Date(0, 0, 0, 0, 0, totalSecs, 0, time.UTC)
    
        date := base.Add(nanosecs)
    
        fmt.Printf("Result: %s", date)
    
    }
    

prog.go:21: cannot use nanosecs (type int64) as type time.Duration in function
argument

<http://play.golang.org/p/XWSK_QaXrQ>

What I'm missing?  
Thanks


Answer: 
    package main
    
    import (
            "fmt"
            "time"
    )
    
    func main() {
            baseTime := time.Date(1980, 1, 6, 0, 0, 0, 0, time.UTC)
            date := baseTime.Add(1722*7*24*time.Hour + 24*time.Hour + 66355*time.Second)
            fmt.Println(date)
    }
    

[Playground](http://play.golang.org/p/l2pV8wQBQC)

* * *

Output

    
    
    2013-01-07 18:25:55 +0000 UTC
    

