diff --git a/package.json b/package.json index 7d827ae..ae61d43 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "dependencies": { "@slack/bolt": "^1.2.0", "date-fns": "^2.0.1", + "date-fns-tz": "^1.0.7", "get-video-id": "^3.1.4", "glob": "^7.1.4", "kuromoji": "^0.1.2", diff --git a/scripts/weather.js b/scripts/weather.js index 8158def..d83bbe0 100644 --- a/scripts/weather.js +++ b/scripts/weather.js @@ -1,27 +1,36 @@ const subMinutes = require("date-fns/subMinutes"); const roundToNearestMinutes = require("date-fns/roundToNearestMinutes"); -const format = require("date-fns/format"); +const format = require("date-fns-tz/format"); +const utcToZonedTime = require("date-fns-tz/utcToZonedTime"); const nyanco = require("./util/nyanco"); +const timeZone = "Asia/Tokyo"; const prefNumber = 34; const pageURL = `https://www.tenki.jp/radar/7/${prefNumber}/`; const imgURL = target => [ "https://static.tenki.jp/static-images/radar/", - format(target, "yyyy/MM/dd/HH/mm/ss"), + format(target, "yyyy/MM/dd/HH/mm/ss", { timeZone }), `/pref-${prefNumber}-large.jpg` ].join(""); module.exports = [ /天気/, async ({ say }) => { - const target = roundToNearestMinutes(subMinutes(new Date(), 5), { - nearestTo: 5 - }); + const target = utcToZonedTime( + roundToNearestMinutes(subMinutes(new Date(), 5), { + nearestTo: 5 + }), + timeZone + ); say( [ - `${nyanco()} < ${format(target, "HH時mm分の雨雲の様子にゃーん")}`, + `${nyanco()} < ${format( + target, + "HH時mm分の雨雲の様子にゃーん", + timeZone + )}`, imgURL(target), pageURL ].join("\n") diff --git a/yarn.lock b/yarn.lock index 37aeef3..819a666 100644 --- a/yarn.lock +++ b/yarn.lock @@ -228,6 +228,11 @@ cookie@0.4.0: resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.0.tgz#beb437e7022b3b6d49019d088665303ebe9c14ba" integrity sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg== +date-fns-tz@^1.0.7: + version "1.0.7" + resolved "https://registry.yarnpkg.com/date-fns-tz/-/date-fns-tz-1.0.7.tgz#1c80f7592cca5da4fd2085132936dcc7fa9afecd" + integrity sha512-oNfi/3IxRfmysRIT+QJMbO/44Uj10nApAYJvlayTmNRFZG+JqdOJYXm1DWU65DNlG/ySbuQwpFkGIa3b2XFUVw== + date-fns@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.0.1.tgz#c5f30e31d3294918e6b6a82753a4e719120e203d"