make(Language::class); $translator = \Carbon\Translator::get('nl_NL'); $translator->setTranslations([ 'weekdays_short' => explode(',', $language->__('language.dayNamesShort')), 'weekdays_min' => explode(',', $language->__('language.dayNamesMin')), 'months_short' => explode(',', $language->__('language.monthNamesShort')), 'mmm_suffix' => '', ]); $translator = \Carbon\Translator::get('nl'); $translator->setTranslations([ 'weekdays_short' => explode(',', $language->__('language.dayNamesShort')), 'weekdays_min' => explode(',', $language->__('language.dayNamesMin')), 'months_short' => explode(',', $language->__('language.monthNamesShort')), 'mmm_suffix' => '', ]); } } /** * Formats the current date for the user based on the user's timezone, * language, and date format. * * @return \Closure Returns a closure that accepts no arguments and returns * the formatted date as per the user's settings. */ public function formatDateForUser(): \Closure { $mixin = $this; return function () use ($mixin): string { return self::this() ->locale($mixin->userLanguage) ->setTimezone($mixin->userTimezone) ->translatedFormat($mixin->userDateFormat); }; } /** * Formats the current time for the user based on the user's timezone, * language, and time format. * * @return \Closure Returns a closure that accepts no arguments and returns * the formatted time as per the user's settings. */ public function formatTimeForUser(): \Closure { $mixin = $this; return function () use ($mixin): string { return self::this() ->setTimezone($mixin->userTimezone) ->locale($mixin->userLanguage) ->translatedFormat($mixin->userTimeFormat); }; } /** * Formats the current time for the user based on the user's timezone, * language, and time format. * * @return \Closure Returns a closure that accepts no arguments and returns * the formatted time as per the user's settings. */ public function format24HTimeForUser(): \Closure { $mixin = $this; return function () use ($mixin): string { return self::this() ->setTimezone($mixin->userTimezone) ->locale($mixin->userLanguage) ->translatedFormat('H:i'); }; } /** * Formats the current date and time for storing in the database based on * the database timezone, user language, and database format. * * @return \Closure Returns a closure that accepts no arguments and returns * the formatted date and time as per the database settings. */ public function formatDateTimeForDb(): \Closure { $mixin = $this; return function () use ($mixin): string { return self::this() ->setTimezone($mixin->dbTimezone) ->locale($mixin->userLanguage) ->format($mixin->dbFormat); }; } /** * Sets the current timezone and locale to the user's timezone and language. * * @return \Closure Returns a closure that accepts no arguments and sets the * timezone and locale to the user's settings. */ public function setToUserTimezone(): \Closure { $mixin = $this; return function () use ($mixin): CarbonImmutable { return self::this() ->setTimezone($mixin->userTimezone) ->locale($mixin->userLanguage); }; } /** * Sets the timezone of the current datetime object to the database timezone * and sets the locale to the user's language. * * @return \Closure Returns a closure that accepts no arguments and returns the * current datetime object with the timezone and locale set. */ public function setToDbTimezone(): \Closure { $mixin = $this; return function () use ($mixin): CarbonImmutable { return self::this() ->setTimezone($mixin->dbTimezone) ->locale($mixin->userLanguage); }; } }