-
Notifications
You must be signed in to change notification settings - Fork 3
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
Date shown in the widget is always showing month + 1 #6
Comments
There looks to be a logical fault in the Helper # What it is doing is that when you call the method
in your model passing it the date string or object it returns back the As in javascript try example in your console
So in this case the helper is passing the month date and year by using php date function like # You need to change the javascript expression returned by the function either return the expression with string or provide all the parameters manually. But since the helper has all static functions and you cant extend them i would suggest
If for some reason the calendar does not work with that format change it to the following and it will work
You can copy the following to your folder
You Event Model should look like
|
I think the problem is not even this. I use the following expression: /**
* @return \yii\web\JsExpression
*/
public function getStartDate() {
return JsExpressionHelper::parse($this->date, 'Y-n-j');
} I get the correct JS line : "startDate":new Date(2018, 3, 29),
"endDate":new Date(2018, 3, 29) But, the date still shifts for a month ahead. The problem is that in JS months begin with 0. Therefore, even if you pass immediately the correct date format. The final date will be shifted to +1. MDN /**
* @return \yii\web\JsExpression
*/
public function getStartDate() {
$datetime = new \DateTime($this->date);
$date = $datetime->sub(new \DateInterval('P1M'));
return JsExpressionHelper::parse($date->format('Y-n-j'));
} |
@s1lver with your approach how does january gets converted? wouldnt it switch to december previous year? and what happens with dates which are not existent previous year, for example converting march 31 to february 31? |
You're right. Perhaps this solution is better. /**
* @return JsExpression
* @throws \Exception
*/
public function getStartDate() {
$datetime = new \DateTime($this->date);
$month = $datetime->format('m') - 1;
$day = $datetime->format('d');
$year = $datetime->format('Y');
return new JsExpression('new Date('.$year.','.$month.','.$day.')');
} |
Thank you for this extension. I'm trying to integrate it into my yii2 website. I'm using active data provider like in the code below but each calendar item is showing wrong month. eg item from 19th of May is showing 19th of June in the widget (please see the picture attached). Could you advised please what might be the issue ?
The text was updated successfully, but these errors were encountered: