-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkrtime.go
More file actions
32 lines (26 loc) · 764 Bytes
/
krtime.go
File metadata and controls
32 lines (26 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Package krtime provides helper functions that ease to use time.Time in Korea.
//
// No more `seoul, err := time.LoadLocation("Asia/Seoul"); if err != nil { ... }; t := time.Now().In(seoul)`.
package krtime
import (
"fmt"
"time"
)
// Seoul represents *time.Location of Seoul in Korea.
var Seoul *time.Location
func init() {
locationName := "Asia/Seoul"
var err error
Seoul, err = time.LoadLocation(locationName)
if err != nil {
panic(fmt.Errorf("krtime: init: load location %q: %v", locationName, err))
}
}
// New converts time.Time with the location information set to "Asia/Seoul".
func New(t time.Time) time.Time {
return t.In(Seoul)
}
// Now returns the current time in location "Asia/Seoul".
func Now() time.Time {
return New(time.Now())
}