-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/posting time control #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
cb05070
762ee88
7432416
9553674
f531049
c9f0a89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,9 +11,9 @@ class Text | |
| * | ||
| * @return bool | ||
| */ | ||
| public static function isEmail(string $email): bool | ||
| public static function isEmail(string $str): bool | ||
| { | ||
| return filter_var($email, FILTER_VALIDATE_EMAIL) === false ? false : true; | ||
| return filter_var($str, FILTER_VALIDATE_EMAIL) === false ? false : true; | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -37,4 +37,23 @@ public static function hasMin(int $lim, string $str): bool | |
| { | ||
| return strlen($str) >= $lim; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Test if string is date | ||
| * | ||
| * @return bool | ||
| */ | ||
| public static function isTimestamp(string $str): bool | ||
| { | ||
| $ts = \App\Lib\Util\Timestamp::timestampToArray($str); | ||
| if (checkdate($ts['m'], $ts['d'], $ts['y']) && | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can validate timestamp format by https://www.php.net/manual/en/function.strtotime.php it returns false if format is not valid.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes can be, but i dont think i could check for yyyy-mm-ddThh:ii and pass it accordingly, also we'd loose the ability of easy checks for separate values, like:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is true, but that is meant that 2021-01-01 will not be treated as valid timestamp despite the fact it can be converted into unix timestamp. Same with passing only time. |
||
| $ts['h'] >= 0 && $ts['h'] <= 23 && | ||
| $ts['i'] >= 0 && $ts['i'] <= 59 && | ||
| $ts['s'] >= 0 && $ts['s'] <= 59) { | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Lib\Util; | ||
|
|
||
| use Exception; | ||
|
|
||
| class Timestamp | ||
| { | ||
| /** | ||
| * Retruns array from date string | ||
| * | ||
| * @param string $str | ||
| * @return array<int> | ||
| */ | ||
| public static function timestampToArray(string $str): array | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you check https://www.php.net/manual/en/book.datetime.php? If it has all the features, we can use that class instead. |
||
| { | ||
| if (strpos($str, ' ')) { | ||
| $ts = explode(' ', $str); | ||
| } else if (strpos($str, 'T')) { | ||
| $ts = explode('T', $str); | ||
| $ts[1] .= ':00'; | ||
| } else { | ||
| throw new Exception('Timestamp is Not in right format YYYY-MM-DD HH:II:SS', 400); | ||
| } | ||
|
|
||
| $date = explode('-', $ts[0]); | ||
| $time = explode(':', $ts[1]); | ||
|
|
||
| if (sizeof($date) == 3 && sizeof($time) == 3 && | ||
| is_numeric($date[0]) && is_numeric($date[1]) && is_numeric($date[2]) && | ||
| is_numeric($time[0]) && is_numeric($time[1]) && is_numeric($time[2])) { | ||
| return (array('y' => intval($date[0]), 'm' => intval($date[1]), 'd' => intval($date[2]), 'h' => intval($time[0]), 'i' => intval($time[1]), 's' => intval($time[2]))); | ||
| } else { | ||
| throw new Exception('Timestamp is Not in right format YYYY-MM-DD HH:II:SS', 400); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing @param string $str.