Skip to content

Commit

Permalink
Monthly period fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zgrguric committed Mar 14, 2024
1 parent d0ba136 commit 971da76
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/Console/Commands/XwaAccountSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
14 changes: 13 additions & 1 deletion app/Helpers/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,16 @@ function bcdechex(string $dec): string
$test2 = \bcdechex($test);
var_dump($test2);
exit;
*/
*/

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]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 971da76

Please sign in to comment.