Skip to content

LoadLocation Call in time package #64

Closed
@rusco

Description

@rusco
package main

import (
    "fmt"
    "math"
    "time"
)

func calcDuration(hrStart, minStart, hrEnd, minEnd int) (hrDiff, minDiff int) {

    // next line crashes on Win7/go1.3, systemcalls not supported:
    //pt, _ := time.LoadLocation("Europe/Lisbon")

    //this works fine:
    pt := time.UTC

    yr, mo, dy := time.Now().Date()

    t1 := time.Date(yr, mo, dy, hrStart, minStart, 0, 0, pt)
    t2 := time.Date(yr, mo, dy, hrEnd, minEnd, 0, 0, pt)

    overallDiff := t2.Sub(t1).Minutes()
    hrDiff = int(math.Floor(overallDiff / 60))
    minDiff = int(math.Mod(overallDiff, 60))

    return
}

func main() {

    hr, mi := calcDuration(8, 15, 19, 35)
    fmt.Printf("Duration: %d hours and %d minutes.\n", hr, mi)
}

the "time.LoadLocation" call causes a System call, at least on Windows.
I don't know how hard it is to implement this, but could you at least
make a hint in the compatibility doc ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions