/** * Returns an instance of our DateTime object * @return \Carbon\Carbon */ public function getDt() { if (is_null($this->dt)) { $this->dt = new Carbon(); $this->dt->setTimezone($this->getTz()); } return $this->dt; }
public function update(Request $request, $id) { $session_id = Session::getId(); if (!$session_id) { return response('', 400); } $this->validate($request, ['id' => 'required|integer']); $bookmark = Bookmark::find($id); if ($request->bookmark) { $bookmark->bookmark = $request->bookmark; $bookmark->save(); } if ($request->bookmarked_at) { $bookmarked_at = new Carbon($request->bookmarked_at, auth()->user()->timezone); $bookmarked_at->setTimezone('UTC'); $bookmark->bookmarked_at = $bookmarked_at->toDateTimeString(); $bookmark->save(); } return response('', 204); }
/** * Ended in the past. * * @since 3.0.0 * * @return bool */ public function ended_past() { return !is_null($this->end_dt) ? $this->end_dt->setTimezone($this->timezone)->isPast() : false; }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(UpdateEventRequest $req, $slug) { $input = $req->all(); // Ensures database times are always in UTC. foreach ($input as $key => $value) { // Ensures only time fields are changed. if (!strpos($key, 'time')) { continue; } // Converts time from PST to UTC. $pst = new Carbon($value, 'America/Los_Angeles'); $utc = $pst->setTimezone('UTC'); // Sets date/time string back into values for database. $input[$key] = $utc->toDateTimeString(); } Event::findBySlug($slug)->update($input); return redirect()->action('EventsController@show', $slug); }
function ivy_echo_date(\Carbon\Carbon $date) { $date->setTimezone(config('params.user_timezone')); return $date->isToday() ? 'Mới @' . $date->format(config('params.user_hourformat')) : ($date->isYesterday() ? 'Hôm qua @' . $date->format(config('params.user_hourformat')) : $date->format(config('params.user_dateformat'))); }
/** * Get raw entries with a selected set of values to grab. */ public function rawLogEntriesTable() { $title = 'Raw log entries'; $fields = Config::get('marauder.rawLogEntries'); // all of the users log entries: $get = ['log_entries.id', 'structures.time_zone', 'log_entries.time', 'devices.name']; $query = LogEntry::leftJoin('devices', 'devices.id', '=', 'log_entries.device_id')->leftJoin('structures', 'structures.id', '=', 'devices.structure_id')->where('structures.user_id', Auth::user()->id)->take(Config::get('marauder.logTableLimit'))->orderBy('time', 'DESC')->orderBy('devices.id', 'ASC'); // ignore stuff from the query: $ignore = ['id', 'time_zone']; foreach ($fields as $field) { $query->withLogValue($field); $get[] = $field . '.value as ' . $field; } $result = $query->get($get); if ($result->count() > 0) { $result = $result->toArray(); } foreach ($result as $key => $entry) { foreach ($entry as $name => $value) { if ($name == 'time') { // time zone correction! $value = new Carbon($value, 'UTC'); $timezone = strlen($result[$key]['time_zone']) > 0 ? $result[$key]['time_zone'] : 'Europe/Amsterdam'; $value->setTimezone($timezone); } $result[$key][$name] = Format::format($name, $value); } } return View::make('raw.table', compact('result', 'ignore', 'title')); }
/** * Gets the weather from Yahoo!, which is more reliable. */ public function getYahooWeatherInfo() { echo "<pre>\n"; $manualSearch = new Collection(); foreach (Structure::get() as $structure) { if (strlen($structure->postal_code) > 0 && strlen($structure->country_code) > 0) { // find City in database? /** @var City $city */ $city = City::firstOrCreate(['postal_code' => $structure->postal_code, 'country_code' => $structure->country_code]); } else { // Fall back to Utrecht, the netherlands (central station area): $city = City::firstOrCreate(['postal_code' => '3511CE', 'country_code' => 'NL']); } $manualSearch->push($city); } $manualSearch = $manualSearch->unique(); // Yahoo weather is always per city. /** @var City $manualEntry */ foreach ($manualSearch as $city) { // function wont do stuff when its already filled. $this->_helper->getGeoFromYahoo($city); $weatherObject = $this->_helper->getYahooWeatherForCity($city); echo 'Now searching for city #' . $city->id . ', [postal code: ' . $city->postal_code . ', country code: ' . $city->country_code . ']' . "\n"; echo 'City has timezone ' . $city->time_zone . ' and woe-id ' . $city->woeid . "\n"; // try to get as many results from this as possible if (isset($weatherObject->query->results)) { $channel = $weatherObject->query->results->channel; // create report entry first: $report = new Report(); $report->city()->associate($city); $report->time = new Carbon(); $report->save(); // start saving data: // sunrise: $sysSunrise = new Carbon($channel->astronomy->sunrise, $city->time_zone); $sysSunrise->setTimezone('UTC'); $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'sys.sunrise'; $entry->value = $sysSunrise->format('U'); $entry->save(); // sunset: $sysSunset = new Carbon($channel->astronomy->sunset, $city->time_zone); $sysSunset->setTimezone('UTC'); $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'sys.sunset'; $entry->value = $sysSunset->format('U'); $entry->save(); // current temperature: $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'main.temp'; $entry->value = floatval($channel->item->condition->temp); $entry->save(); // current humidity: $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'main.humidity'; $entry->value = floatval($channel->atmosphere->humidity); $entry->save(); // current pressure: $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'main.pressure'; $entry->value = floatval($channel->atmosphere->pressure); $entry->save(); // max predicted for today. $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'main.temp_max'; $entry->value = floatval($channel->item->forecast[0]->high); $entry->save(); // min predicted for today. $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'main.temp_min'; $entry->value = floatval($channel->item->forecast[0]->low); $entry->save(); // wind speed $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'wind.speed'; $entry->value = floatval($channel->wind->speed); $entry->save(); // wind degrees $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'wind.deg'; $entry->value = floatval($channel->wind->direction); $entry->save(); // rain 1h? SKIPPED // weather.main $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'weather.main'; $entry->value = trim($channel->item->condition->text); $entry->save(); // weather.description $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'weather.description'; $entry->value = trim($channel->item->description); $entry->save(); echo 'Saved ' . $report->reportValues()->count() . ' weather reports for city #' . $city->id . "\n\n"; } else { echo 'No results for city [' . $city->postal_code . ', ' . $city->country_code . ']' . "\n\n"; } } }
/** * convert carbon date to UTC timezone * * @param \Carbon\Carbon $date * * @return static */ public static function convertToUTC(Carbon $date) { return $date->setTimezone('UTC'); }