From 971da7611a332a51db6c4f9f1548b4fe40183ac6 Mon Sep 17 00:00:00 2001 From: zgrguric Date: Thu, 14 Mar 2024 11:04:09 +0100 Subject: [PATCH] Monthly period fix --- app/Console/Commands/XwaAccountSync.php | 3 ++- app/Helpers/helpers.php | 14 +++++++++++++- ...2022_11_24_083404_create_transactions_table.php | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/XwaAccountSync.php b/app/Console/Commands/XwaAccountSync.php index 69781f3..bc15579 100644 --- a/app/Console/Commands/XwaAccountSync.php +++ b/app/Console/Commands/XwaAccountSync.php @@ -162,7 +162,8 @@ public function handle() if($ledger_index_min != 0 && config('xwa.database_engine') == 'sql') { //find last tx in sharded db, back from today to genesis (first one found is it) $period_startdate = ripple_epoch_to_carbon(config('xrpl.'.config('xrpl.net').'.genesis_ledger_close_time')); - $period = \Carbon\CarbonPeriod::create($period_startdate, '30 days', now()); + //$period = \Carbon\CarbonPeriod::create($period_startdate, '30 days', now()); + $period = toMonthPeriod($period_startdate,now()); $period_array = []; foreach($period as $m) { $period_array[] = $m->format('Ym'); diff --git a/app/Helpers/helpers.php b/app/Helpers/helpers.php index 1a8b48d..b6eba8c 100644 --- a/app/Helpers/helpers.php +++ b/app/Helpers/helpers.php @@ -359,4 +359,16 @@ function bcdechex(string $dec): string $test2 = \bcdechex($test); var_dump($test2); exit; -*/ \ No newline at end of file +*/ + +if (!function_exists('toMonthPeriod')) { + /** + * dechex but suppported uint64 numbers + */ + function toMonthPeriod(\Carbon\Carbon $from, \Carbon\Carbon $to): \Carbon\CarbonPeriod + { + $from2 = clone $from; + $from2->firstOfMonth(); + return $from2->toPeriod($to, 1, 'month')->settings(['monthOverflow' => false]); + } +} \ No newline at end of file diff --git a/database/migrations/2022_11_24_083404_create_transactions_table.php b/database/migrations/2022_11_24_083404_create_transactions_table.php index 8c6a119..419f0a2 100644 --- a/database/migrations/2022_11_24_083404_create_transactions_table.php +++ b/database/migrations/2022_11_24_083404_create_transactions_table.php @@ -212,7 +212,7 @@ private function period(): CarbonPeriod { $startdate = ripple_epoch_to_carbon(config('xrpl.'.config('xrpl.net').'.genesis_ledger_close_time')); $enddate = now()->addYears(2); - return CarbonPeriod::create($startdate, '30 days', $enddate); + return toMonthPeriod($startdate,$enddate); } /**