Facebook
From Rajni, 2 Years ago, written in PHP.
This paste is a reply to Re: 3 Questions from Obese Meerkat - view diff
Embed
Download Paste or View Raw
Hits: 142
  1. //Do you mind answering 3 quick problem solving questions here in chat?
  2.  
  3. // Question 1, look at the code below. Pls tell me the bug?
  4. $last_days = [];
  5.  
  6. for($i=1; $i <= 3; $i++; ){
  7.         $last_days[] = date('Y-m-d', strtotime('-$i weekdays'));
  8. }
  9.  
  10. $tx_list = Transaction::whereIn('method', Transaction::$retail_types)
  11.                         ->where('status','=','pending')
  12.                         ->where('created_at', 'in', $last_days);
  13.                        
  14.  
  15. foreach($tx_list as $tx){
  16.         $service->callbackRetailPaid($tx->xendit_external_id, 'COMPLETED');
  17. }
  18.  
  19. /*
  20. Question 2:
  21. Looking at the code above, seems like it gets all transactions that were created 3 days ago....
  22. How can we change that so we get all transactions that were created 3 days ago excluding weekend (saturday, sunday)?
  23. E.g: Transactions that were created on Monday will be picked up Thursday at 2pm,
  24. but Transactions that were created on Friday should be picked up the following Wed at 2pm
  25.  
  26. 3. Bonus: How to only pick up transactions 3 business days ago (excluding weekends and USA public holiday)?
  27. */