/**
  * 天気情報を成形して取得する
  *
  * @param   \chomado\bot\weather\yahoocom\Response $data Y!Weatherレスポンスデータ
  * @param   string        $location 地名情報 e.g. 東京
  * @param   \DateTimeZone $timeZone 表示に利用するタイムゾーン
  * @return  string
  */
 public static function formatForWeatherTweet(WeatherResponse $weather, $location, DateTimeZone $timeZone)
 {
     $condition = $weather->getCondition();
     $tomorrow = $weather->getTomorrow();
     // 表示用タイムゾーンの設定
     $updatedAt = clone $condition->updatedAt;
     $updatedAt->setTimezone($timeZone);
     $format = "%1\$sの%2\$s現在の天気は、%3\$s(%4\$.1f℃)です。\n" . "明日は%5\$sで、最高気温%6\$.1f℃、最低気温%7\$.1f℃です。";
     return sprintf($format, $location, $updatedAt->format('H:i'), $condition->weather->getJapaneseText(), $condition->temp->getAsCelsius(), $tomorrow->weather->getJapaneseText(), $tomorrow->tempHigh->getAsCelsius(), $tomorrow->tempLow->getAsCelsius());
 }
Example #2
0
 public function testLoadFromJson2()
 {
     $o = new Response(file_get_contents(__DIR__ . '/response.2.json'));
     $now = $o->getCondition();
     $this->assertEquals(27, $now->weather->getCode());
     $this->assertEquals('Mostly Cloudy', $now->weather->getEnglishText());
     $this->assertEquals(48, $now->temp->getAsFahrenheit());
     $this->assertEquals(1424867340, $now->updatedAt->getTimestamp());
     $tomorrow = $o->getTomorrow();
     $this->assertEquals(12, $tomorrow->weather->getCode());
     $this->assertEquals('Rain', $tomorrow->weather->getEnglishText());
     $this->assertEquals(48, $tomorrow->tempHigh->getAsFahrenheit());
     $this->assertEquals(42, $tomorrow->tempLow->getAsFahrenheit());
     $at = $o->getUpdatedAt();
     $this->assertEquals(1424867340, $at->getTimestamp());
 }