n()->micro, 'timestamp' => $this->toCarbon()->timestamp, 'formatted' => $this->toString(), 'timezone' => $this->timezone, ]; } public function getDayOfWeek(): int { if ($this->isSaturday()) { return 0; } if ($this->isSunday()) { return 1; } if ($this->isMonday()) { return 2; } if ($this->isTuesday()) { return 3; } if ($this->isWednesday()) { return 4; } if ($this->isThursday()) { return 5; } return 6; } public function isSunday(): bool { return $this->isDayOfWeek(Carbon::SUNDAY); } public function isMonday(): bool { return $this->isDayOfWeek(Carbon::MONDAY); } public function isTuesday(): bool { return $this->isDayOfWeek(Carbon::TUESDAY); } public function isWednesday(): bool { return $this->isDayOfWeek(Carbon::WEDNESDAY); } public function isThursday(): bool { return $this->isDayOfWeek(Carbon::THURSDAY); } public function getDayOfYear(): int { $dayOfYear = 0; for ($m = 1; $m < $this->getMonth(); $m++) { if ($m <= 6) { $dayOfYear += 31; continue; } if ($m < 12) { $dayOfYear += 30; continue; } } return $dayOfYear + $this->getDay(); } public function toString(): string { return $this->format('Y-m-d H:i:s'); } public function format(string $format): string { return CalendarUtils::strftime($format, $this->toCarbon()); } public function __toString(): string { return $this->toString(); } public function ago(): string { $now = time(); $time = $this->getTimestamp(); // catch error if (!$time) { return false; } // build period and length arrays $periods = ['ثانیه', 'دقیقه', 'ساعت', 'روز', 'هفته', 'ماه', 'سال', 'قرن']; $lengths = [60, 60, 24, 7, 4.35, 12, 10]; // get difference $difference = $now - $time; // set descriptor if ($difference < 0) { $difference = abs($difference); // absolute value $negative = true; } // do math for ($j = 0; $difference >= $lengths[$j] and $j < count($lengths) - 1; $j++) { $difference /= $lengths[$j]; } // round difference $difference = intval(round($difference)); // return return number_format($difference) . ' ' . $periods[$j] . ' ' . (isset($negative) ? '' : 'پیش'); } public function getTimestamp(): int { return $this->toCarbon()->getTimestamp(); } public function getNextWeek(): Jalalian { return $this->addDays(7); } public function getLastWeek(): Jalalian { return $this->subDays(7); } public function addDays(int $days = 1): Jalalian { return static::fromCarbon($this->toCarbon()->addDays($days)); } public function addDay(): Jalalian { return $this->addDays(1); } public function getNextMonth(): Jalalian { return $this->addMonths(1); } public function getLastMonth(): Jalalian { return $this->subMonths(1); } public function getWeekOfMonth(): int { return floor(($this->day + 5 - $this->getDayOfWeek()) / 7) + 1; } }