#Trouble checking if a transaction is 60 seconds ago

1 messages · Page 1 of 1 (latest)

gleaming sequoia
#

I have been struggling to create a function that returns true if the latest transaction is 60 seconds ago and return false if it's not but nothing ever works this is my function ```php
function is60($email, $ref) {
$first = Transaction::where('email', $email)->select('created_at', 'my_ref')->latest()->first();
if ($first) {
$givenTime = Carbon::parse('2025-02-22 19:11:47', 'Africa/Lagos');
$comparisonTime = Carbon::now('Africa/Lagos')->subSeconds(60);

    Log::info('Ref:', ['ref_at' => $ref]);
    Log::info('compare Ref:', ['ref_at' => $first->my_ref]);
    Log::info('Created At:', ['created_at' => $givenTime]);
    Log::info('Comparison Time:', ['threshold_time' => $comparisonTime]);

    if ($givenTime->lessThan($comparisonTime) || $first->my_ref == $ref) {
        return 'true';
    }
}
return 'false';

}```
This function returns always returns true regardless of whether that date is 60 seconds ago or not

spare flower
#

I could be wrong but because you have the OR clause then $first->my_ref == $ref can also be true..maybe try it without that and see if it fixes the problem..

gleaming sequoia
spare flower
#

Yeah I'm just saying if any of the conditions in the OR operator are true then you'll always get true - so 'maybe' that's the reason you see true when you expect false due to the time but actually it's because of the $ref value..