Skip to content

Commit

Permalink
海外のタイムゾーンにいても、東京の雨模様が見れる!
Browse files Browse the repository at this point in the history
  • Loading branch information
otiai10 committed Oct 25, 2019
1 parent 7860634 commit c4ae223
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
9 changes: 7 additions & 2 deletions cli/amesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ package cli
import (
"fmt"
"os"
"time"

"github.com/otiai10/amesh/lib/amesh"
"github.com/otiai10/gat/render"
)

// Amesh デフォルトのアメッシュを表示
func Amesh(r render.Renderer, geo, mask bool) error {
entry := amesh.GetEntry(time.Now())

now, err := getNow()
if err != nil {
return err
}

entry := amesh.GetEntry(now)
merged, err := entry.Image(geo, mask)
if err != nil {
return err
Expand Down
16 changes: 16 additions & 0 deletions cli/now.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package cli

import "time"

const defaultLocation = "Asia/Tokyo"

// FIXME: ameshは東京のやつなのでとりあえずAsia/Tokyoだけにします。
// ゆうて日本国内なら同じtimezoneなのであんまり問題無いと思うけど、
// 今後世界都市対応するなら、これは問題になりますね。
func getNow() (time.Time, error) {
location, err := time.LoadLocation(defaultLocation)
if err != nil {
return time.Time{}, err
}
return time.Now().In(location), nil
}
7 changes: 6 additions & 1 deletion cli/timelapse.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ func Timelapse(r render.Renderer, minutes, delay int, loop bool) error {

func getSnapshots(dur time.Duration) (snapshots []snapshot, err error) {

now, err := getNow()
if err != nil {
return nil, err
}

sheets := int((int64(dur) / int64(5*time.Minute))) + 1
for i := 0; i < sheets; i++ {
t := time.Now().Add(time.Duration(-5*(sheets-i)) * time.Minute)
t := now.Add(time.Duration(-5*(sheets-i)) * time.Minute)
entry := amesh.GetEntry(t)
img, err := entry.Image(true, true)
if err != nil {
Expand Down
12 changes: 0 additions & 12 deletions lib/amesh/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,6 @@ func getMesh(t time.Time) string {
return AmeshURL + t.Format(mesh)
}

// // YAGNI!!
// func now(loc *time.Location) time.Time {
// if loc != nil {
// return time.Now().In(loc)
// }
// loc, err := time.LoadLocation(defaultLocation)
// if err != nil {
// return time.Now()
// }
// return time.Now().In(loc)
// }

// Image fetches image data from URL and merge them if needed.
func (entry Entry) Image(geo, mask bool, client ...*http.Client) (*image.RGBA, error) {

Expand Down

0 comments on commit c4ae223

Please sign in to comment.