-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Format "2024-02-29" to Buddhist Era so to obtain "2567-02-29" #2954
Comments
Hello, I'm sorry for that but there is no way to support that. First, there are legit cases where people doing Even if we would like to support that You're recommended to split units not to handle Buddhist Era values using a use Carbon\Carbon;
$gregorianDate = '2024-02-29';
$carbonObject = Carbon::createFromDate($gregorianDate);
$buddhistDate = $carbonObject->addYears(543)->year . $carbonObject->format('-m-d');
echo "AD (Anno Domini): $gregorianDate\n";
echo "BE (Buddhist Era): $buddhistDate\n"; Thanks. |
Thank you for your answer. What do you think ? Add my method "formatBuddhist()" for Buddhist Era year format
If you agree, please add both version 2.x , 3.x versions. |
Hello, I'm not sure yet if this should be included into Carbon itself, go into a separate package, or simply be documented as a macro. I also see few little possible code changes, for instance, it's not useful to step by the timestamp and involve Be careful of Unfortunately, 2.x is now only receiving bugfixes. New features only comes into 3.x. On the other side, using macro, it would work on any object v2 or v3: Carbon::macro('formatBuddhist', static function (string $format): string {
$self = self::this();
$format = strtr($format, [
'o' => '[{1}]',
'Y' => '[{2}]',
'y' => '[{3}]',
]);
$function = $self->localFormatFunction ?: static::$formatFunction;
if (!$function) {
$format = $self->rawFormat($format);
} else if (\is_string($function) && method_exists($self, $function)) {
$format = [$self, $function];
$format = $function(...\func_get_args());
}
$buddhistYear = $self->year + 543;
return strtr($format, [
'[{1}]' => $self->format('o') + 543,
'[{2}]' => $buddhistYear,
'[{3}]' => str_pad($buddhistYear % 100, 2, '0', STR_PAD_LEFT),
]);
}); |
Hello Thank you so much for everything, suggestion and for your "Carbon" i love it.
https://en.wikipedia.org/wiki/Buddhist_calendar Actually, I think adding to carbon is also possible. Just a few lines more, or we can separate it into a separate package. Have a good day, Thanks |
Hello,
Convert year "2024-02-29" to Buddhist Era, the result month is incorrect "2567-03-01"
https://play.phpsandbox.io/nesbot/carbon/wlJnA5ObQjKQBX89
I encountered an issue with the following code:
Carbon version: 2.72.2 , 3.0.2
PHP version: 7.4.33, 8.2.15
I expected to get:
"2024-02-29" -> "2567-02-29"
Thanks!
The text was updated successfully, but these errors were encountered: