Skip to content
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

Fixed issue #883 #884

Closed
wants to merge 1 commit into from
Closed

Fixed issue #883 #884

wants to merge 1 commit into from

Conversation

Ovsyanka
Copy link
Contributor

@Ovsyanka Ovsyanka commented Feb 3, 2017

No description provided.

@lucasmichot
Copy link
Collaborator

Very nice @Ovsyanka - let me have a look at it later

@Ovsyanka
Copy link
Contributor Author

Ovsyanka commented Feb 3, 2017

It also should fix #887, #863, #871

Copy link
Collaborator

@lucasmichot lucasmichot left a comment

Choose a reason for hiding this comment

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

Some small changes, but looks good !

if ($this->local) {
return parent::modify($modify);
}
$shouldBeModifiedInUtc = preg_match('/(sec|second|min|minute|hour)s?/', $modify);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is a variable really useful here?


/**
* @dataProvider getDealWithDayLightTests
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

@param docblocks missing :-(

$date = new Carbon($dateString, $timezone);
$date->modify($modify);
$this->assertSame($expected, $date->format('Y-m-d H:i:s P'));
$this->assertInstanceOf('Carbon\Carbon', $date);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Feel free to use assertInstanceOfCarbon

$instance = parent::modify($modify);
$this->setTimezone($timezone);
if ($shouldBeModifiedInUtc) {
$timezone = $this->getTimezone();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe use a negated assertion and an early return here ?

@Ovsyanka
Copy link
Contributor Author

Ovsyanka commented Feb 5, 2017

Okay! I will make done it very soon.
The first two remarks are more about code style. But i think it is not a question to discuss, so i will change in the way you suggested.
The last two very reasonable, i will fix it too.

@lucasmichot
Copy link
Collaborator

👍

@Ovsyanka
Copy link
Contributor Author

Ovsyanka commented Feb 5, 2017

Oh, i need to clarify - how i have to handle it. Should i make another commit in that branch or just make another pull-request? it is my first real pull-request =)

@lucasmichot
Copy link
Collaborator

lucasmichot commented Feb 5, 2017 via email

@Ovsyanka
Copy link
Contributor Author

Ovsyanka commented Feb 5, 2017

Actially i changed my mind a little, about early return. I think it is not good in this case. I think that it is fine to handle errors, when you just stopping the function and do not doing it's main task. But if you doing useful tasks in different manner, i surely suppose, that you have to use if-else block. It is more clearly to understand.
Do you agree with me? May i let it in that manner?

@lucasmichot
Copy link
Collaborator

Sure @Ovsyanka

@Ovsyanka
Copy link
Contributor Author

Ovsyanka commented Feb 7, 2017

Okay, i already did this in the last commit before your commentю It contains all changes i supposed to do.

@kaufholdr
Copy link

First of all I like this fix.

In my opinion it would be nice to have a small extension in the documentation of modify about when DST is included and when it is ignored.

@Ovsyanka Ovsyanka force-pushed the issue-883 branch 2 times, most recently from 88d3bd5 to 0d94cc9 Compare February 9, 2017 17:37
// If we changing time in some timezone with daylight correction, there can be the case,
// that this correction influence to time in nonwanted way.
// So we have to make this modification in UTC timezone.
if (!preg_match('/(sec|second|min|minute|hour)s?/', $modify)) {

Choose a reason for hiding this comment

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

case-insensitive search ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great suggestion! I will fix it.

@Ovsyanka
Copy link
Contributor Author

I rebased branch to actual master and made regexp case-insensitive.

@lucasmichot lucasmichot reopened this Feb 13, 2017
@lucasmichot
Copy link
Collaborator

Just restarting Travis

@Ovsyanka
Copy link
Contributor Author

Ovsyanka commented Feb 13, 2017

@kaufholdr wrote:

In my opinion it would be nice to have a small extension in the documentation of modify about when DST is included and when it is ignored.

I totally agree with you, but i think it should be in another issue (and pull-request) because that is not nesessary to apply this pull-request. And i dont know where to place such documentstion.

I think there is appropriate existed issue #890

@Ovsyanka
Copy link
Contributor Author

@lucasmichot, why you do not merging this pull-request? Should i do something else?

@bensinclair
Copy link

Would love to see this merged. We are experiencing the same issue and have had to create workarounds.

@oceanwap
Copy link

oceanwap commented Jun 6, 2017

Is anyone going to merge this? It's pending for so long.

@vlakoff
Copy link
Contributor

vlakoff commented Oct 16, 2017

Ouch, I just got notified of this issue too. Looks like this PR deserves a bump :)

// If we changing time in some timezone with daylight correction, there can be the case,
// that this correction influence to time in nonwanted way.
// So we have to make this modification in UTC timezone.
if (!preg_match('/(sec|second|min|minute|hour)s?/i', $modify)) {
Copy link
Contributor

@vlakoff vlakoff Oct 16, 2017

Choose a reason for hiding this comment

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

Technically, this regex is equivalent to /sec|min|hour/i

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, what is the situation concerning the other modifiers ("day", "week", etc.)?

Copy link
Contributor Author

@Ovsyanka Ovsyanka Oct 16, 2017

Choose a reason for hiding this comment

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

Technically - yes, but this is more explicit and obvious for human reading. I will move the long regexp into comments and replace it by short one in the code.

Others is OK. Modifications by units bigger than hour leaves time of the day non changed.
You could add some tests for that, btw.
Hm, actually the pull-request have some tests for this already (day unit).

Copy link
Contributor

@vlakoff vlakoff Oct 16, 2017

Choose a reason for hiding this comment

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

I had to dig a bit to find this documentation page: Relative Formats.

Copy link
Contributor Author

@Ovsyanka Ovsyanka Oct 17, 2017

Choose a reason for hiding this comment

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

I realised that sec matches to "ordinal" second (like first, second, third). But it must not. I am not sure about how to solve this. I have to think about that.

Copy link
Contributor Author

@Ovsyanka Ovsyanka Oct 17, 2017

Choose a reason for hiding this comment

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

I suppose to make something like this: /[+-]?[0-9]+ (sec|min|hour)\w*( ago)?/i.
The idea is: the unit tokens goes only with numbers behind it and|or ago after.
What do you think?

Upd: hmmm. I see potential problems. It could be

  • second hour of <some date> (I have to investigate if it is a problem)
  • 10 hours (If it just set the time of a day this shouldn't be "fixed")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vlakoff, Look at #883 (comment) plz.

All relative modifications, except seconds, minutes and hours was broken because modifications was forced processed in UTC timezone.
Now only seconds, minutes and hours modifications processing in UTC.

For example i have the date 2014-03-30 00:00:00 in Europe/London (new Carbon('2014-03-30 00:00:00, 'Europe/London')), then if i want to increase date by 1 day, i expect 2014-03-31 00:00:00, but if want to increase date by 24 hours, then i expect 2014-03-31 01:00:00, because in this timezone there will be that time after 24 hours (timezone offset changes because of Daylight correction). The same for minutes and seconds.
@lwille
Copy link

lwille commented Jan 11, 2018

Any news?

@Ovsyanka
Copy link
Contributor Author

Ovsyanka commented Jan 11, 2018

I am waiting for votes on my comment #883 (comment). I am not using Carbon by myself, so I don't want to do some work that I am not sure will be needed.

@Ovsyanka
Copy link
Contributor Author

I decide to rid off this pull-request because that is wrong approach to solve the problem. Look at the #883 (comment) for details.

@Ovsyanka Ovsyanka closed this Jan 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants