isoFormat($format)); } public static function getHumanDayOfWeek(string $date): string { $dt = Carbon::parse($date); return Str::ucfirst($dt->dayName); } /** * Случайная дата за последние X лет в формате YYYY-MM-DD * @param int|null $last_years * @return string */ public static function getRandomDate(?int $last_years = 7): string { if (($last_years > ((int)date('Y') - self::MINIMAL_RANDOM_YEAR)) || ($last_years < 0)) { throw new InvalidDateException('last_years', $last_years, 1); } $seconds = rand(0, $last_years * self::SECONDS_IN_YEAR); // случайное число секунд в диапазоне от 0 до Х лет return Carbon::createFromTimestamp(strtotime('now') - $seconds)->isoFormat(self::DB_FORMAT); } /** * @param string $date * @return string */ public static function getDateForDB(string $date): string { return Carbon::parse($date)->isoFormat(self::DB_FORMAT); } /** * @param string $date * @param int $months * @return string */ public static function addMonths(string $date, int $months): string { return Carbon::parse($date)->addMonths($months)->isoFormat(self::DB_FORMAT); } /** * @param string $string * @return bool */ public static function isDate(string $string): bool { if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/",$string)) { return true; } else { return false; } } public static function getDateOfWeek(int $year, int $weekNumber, $dayOfWeek = 1): string { $date = new DateTime(); // Set the date to the specified year and week number, with Monday as the day (1) $date->setISODate($year, $weekNumber, $dayOfWeek); return $date->format('Y-m-d'); } }