BaseService.php 775 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace addons\DoubleCopy\common\services;
  3. use DateTime;
  4. class BaseService extends \services\common\BaseService
  5. {
  6. public function __construct($config = [])
  7. {
  8. parent::__construct($config);
  9. }
  10. /**
  11. * 给定一个开始和结束时间,是否超过了一个月
  12. *
  13. * @param string $startDate
  14. * @param string $endDate
  15. *
  16. * @return bool
  17. */
  18. public function isMoreThanOneMonth(string $startDate, string $endDate) {
  19. $start = new DateTime($startDate);
  20. $end = new DateTime($endDate);
  21. // 计算两个日期之间的间隔
  22. $interval = $start->diff($end);
  23. // 如果间隔的月份数大于等于1,则返回true
  24. return $interval->m >= 1 || $interval->y >= 1;
  25. }
  26. }