Skip to content

Commit

Permalink
Merge c92cc4e into 29bb2b4
Browse files Browse the repository at this point in the history
  • Loading branch information
chadicus committed Jun 13, 2020
2 parents 29bb2b4 + c92cc4e commit 30d61f1
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 6 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ php:
- 7.1
- 7.2
- 7.3
- 7.4
- nightly
env:
- PREFER_LOWEST="--prefer-lowest --prefer-stable"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

[![Documentation](https://img.shields.io/badge/reference-phpdoc-blue.svg?style=flat)](http://www.pholiophp.org/subjective-php/date)

A collection of various PHP classes for use with date, times and timezones.
A collection of various PHP classes for use with dates, times and timezones.

## Requirements

Expand Down
51 changes: 51 additions & 0 deletions src/DateTime/Constants/DateFormatInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace SubjectivePHP\DateTime\Constants;

interface DateFormatInterface
{
/**
* @var string
*/
const DATE_FORMAT_HTTP_HEADER = 'D, d M Y H:i:s T';

/**
* @var string
*/
const DATE_FORMAT_ISO_8601 = 'c';

/**
* @var string
*/
const DATE_FORMAT_LONG_DATE = 'l, F d, Y';

/**
* @var string
*/
const DATE_FORMAT_LONG_TIME = 'H:i:s';

/**
* @var string
*/
const DATE_FORMAT_RFC_2822 = 'r';

/**
* @var string
*/
const DATE_FORMAT_SHORT_DATE = 'm/d/Y';

/**
* @var string
*/
const DATE_FORMAT_SHORT_TIME = 'g:i A';

/**
* @var string
*/
const DATE_FORMAT_SORTABLE_DATETIME = 'Y-m-d H:i:s';

/**
* @var string
*/
const DATE_FORMAT_YEAR_MONTH = 'F Y';
}
75 changes: 75 additions & 0 deletions src/DateTime/Constants/DayOfWeekInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
namespace SubjectivePHP\DateTime\Constants;

interface DayOfWeekInterface
{
/**
* @var string
*/
const ISO_WEDNESDAY = '3';

/**
* @var string
*/
const ISO_THURSDAY = '4';

/**
* @var string
*/
const ISO_FRIDAY = '5';

/**
* @var string
*/
const ISO_SATURDAY = '6';

/**
* @var string
*/
const ISO_SUNDAY = '7';

/**
* @var string
*/
const SUNDAY = '0';

/**
* @var string
*/
const ISO_MONDAY = '1';

/**
* @var string
*/
const ISO_TUESDAY = '2';

/**
* @var string
*/
const MONDAY = '1';

/**
* @var string
*/
const TUESDAY = '2';

/**
* @var string
*/
const WEDNESDAY = '3';

/**
* @var string
*/
const THURSDAY = '4';

/**
* @var string
*/
const FRIDAY = '5';

/**
* @var string
*/
const SATURDAY = '6';
}
9 changes: 4 additions & 5 deletions src/DateTime/Utilities/DateTimeUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
namespace SubjectivePHP\DateTime\Utilities;

use DateTimeInterface;
use SubjectivePHP\DateTime\Constants\DayOfWeekInterface;

/**
* Utility class for DateTimeInterface objects.
*/
abstract class DateTimeUtil
abstract class DateTimeUtil implements DayOfWeekInterface
{
/**
* Returns true if the given date time is a Saturday or Sunday.
Expand All @@ -18,8 +19,7 @@ abstract class DateTimeUtil
*/
final public static function isWeekendDay(DateTimeInterface $dateTime) : bool
{
//ISO-8601 numeric representation of the day of the week, 1 (for Monday) through 7 (for Sunday)
return $dateTime->format('N') > 5;
return (int)$dateTime->format('N') > (int)self::ISO_FRIDAY;
}

/**
Expand All @@ -31,8 +31,7 @@ final public static function isWeekendDay(DateTimeInterface $dateTime) : bool
*/
final public static function isWeekDay(DateTimeInterface $dateTime) : bool
{
//ISO-8601 numeric representation of the day of the week, 1 (for Monday) through 7 (for Sunday)
return $dateTime->format('N') < 6;
return (int)$dateTime->format('N') < (int)self::ISO_SATURDAY;
}

/**
Expand Down

0 comments on commit 30d61f1

Please sign in to comment.