Skip to content

Feat/posting time control#92

Open
oliverstasa wants to merge 6 commits intodevelopfrom
feat/posting_time_control
Open

Feat/posting time control#92
oliverstasa wants to merge 6 commits intodevelopfrom
feat/posting_time_control

Conversation

@oliverstasa
Copy link
Copy Markdown
Member

Should test is timestamp is valid
Also function for parsing timestamp to array using standart: y, m, d, h, i, s

@oliverstasa oliverstasa changed the base branch from master to develop January 28, 2021 14:04
@oliverstasa oliverstasa requested a review from pchalupa January 28, 2021 14:11
@oliverstasa oliverstasa self-assigned this Jan 28, 2021
Copy link
Copy Markdown
Contributor

@pchalupa pchalupa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check it. I've add some advice, maybe it will be helpfull.

public static function isTimestamp(string $str): bool
{
$ts = \App\Lib\Util\Timestamp::timestampToArray($str);
if (checkdate($ts['m'], $ts['d'], $ts['y']) &&
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member Author

@oliverstasa oliverstasa Jan 28, 2021

Choose a reason for hiding this comment

The 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:

$ts = \App\Lib\Util\Timestamp::timestampToArray($str);
$hour = $ts['h'];

Copy link
Copy Markdown
Contributor

@pchalupa pchalupa Jan 29, 2021

Choose a reason for hiding this comment

The 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.


/**
* Test if string is date
*
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing @param string $str.

* @param string $str
* @return array<int>
*/
public static function timestampToArray(string $str): array
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

@oliverstasa
Copy link
Copy Markdown
Member Author

the question is whether to use this format of date, or always turn the date to int a work with the int...

@pchalupa
Copy link
Copy Markdown
Contributor

the question is whether to use this format of date, or always turn the date to int a work with the int...

I need to test it. Body data are always stringified, but when body is parsed, number stirng are overtyped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants