Go to current date

Hello,

I have come across odd behavior when trying to get my calendar to go to the current date.

I have added a button that, when clicked, should bring the user to the current date

        private void CurrentDate_Clicked(object sender, Syncfusion.SfCalendar.XForms.CalendarTappedEventArgs args)
        {
            SfCalendar calendar = Calendar;
            calendar.ViewMode = ViewMode.MonthView;
            calendar.MoveToDate = DateTime.Now;
        }

In UWP, the view does go back to the current day/month, but the dates in calendar get changed (for example, May 1st 2018 shows as Sunday, when it should be Tuesday). In Android, it only works if I am in Month view. If I scroll to a different date when in Year View, then click this button, the calendar view switches from Year View to Month View, but the calendar stays on June of whatever year I was in when I clicked "CurrentDate" (it does not seem to execute the calendar.MoveToDate = DateTime.Now command).

Any suggestions?

Thanks,

Dustin



10 Replies

MS Mugundhan Saravanan Syncfusion Team May 28, 2018 02:16 PM UTC

Hi Dustin,

Thanks for contacting Syncfusion support.

We have checked the reported issue “Click the button its not move to the current date”. We are unable to reproduce the reported issue. We have created a simple sample for your reference. Please have the sample from the following link

Sample: http://www.syncfusion.com/downloads/support/directtrac/general/ze/Calendar_Sample_Button_Click1239567531
 
  
Could you please provide the below mentioned details?

1)Which version are you using for Sfcalendar
2)Modified sample which replicate the reported issue

This will help us to provide appropriate solution for this.

Regards,
Mugundhan S. 



TC Two Chain May 29, 2018 05:01 AM UTC

Thanks for the quick reply!

I tried running your code. If you press the button when in year view, the code does not work. I had to modify it like this:

public partial class MainPage : ContentPage
{
        public MainPage()
        {
            InitializeComponent();
            btn.Clicked += Btn_Clicked;
        }

        private void Btn_Clicked(object sender, EventArgs args)
        {
            calendar.ViewMode = ViewMode.MonthView;
            calendar.MoveToDate = DateTime.Now.Date;
        }
    }


Even after adding the calendar.ViewMode = ViewMode.MonthView;, I still find that in Android, if in year view, the calendar just switches to month view, and stays on June of the year it was on...

I am using v16.1.0.37 of sfcalendar, and Xamarin.Forms 3.0.0.446417.

Any other suggestions?


Update: I found a good work-around for anyone else who runs into this issue. I noticed that when in year view, if I clicked on "current date" the calendar would always just jump to June of whatever year  is in. If then clicked the button again, nothing would happen. However, if I then scrolled to a different month, and pressed the button, the view would go to the correct day/month. Thus, with that in mind, I modified my code as follows:

       private void CurrentDate_Clicked(object sender, Syncfusion.SfCalendar.XForms.CalendarTappedEventArgs args)
        {
            if (Calendar.ViewMode == ViewMode.YearView)
            {
                
                Calendar.ViewMode = ViewMode.MonthView;
                DependencyService.Get().Backward();
                Calendar.MoveToDate = DateTime.Now;
            }
            else
            {
                Calendar.MoveToDate = DateTime.Now;

            }


        }

By forcing the calendar to move to new month when in month view, everything now seems to work in Android. 

However, unfortunately, in UWP, the months and dates still seem to get messed up (e.g. if I move back to May, May 1st is suddenly a Sunday instead of Tuesday). This behavior is very strange, but quite repeatable.

Any comments on this behavior or how to fix it would be appreciated!


MS Mugundhan Saravanan Syncfusion Team May 30, 2018 03:35 PM UTC

Hi Dustin,

Thanks for your update.

We have checked the reported issue ”MovetoDate is not working when the view is in YearView”.We will create report for this issue and the fix for the reported issue will be available in our upcoming volume 2 sp-1 release which will be rolled at end of June month.

We have created workaround sample by using Await.Delay function.Please have the sample from the following link

Sample: http://www.syncfusion.com/downloads/support/directtrac/general/ze/App11052034192
Please let us know if you have any other concern.

Regards,
Mugundhan S.


TC Two Chain May 31, 2018 01:32 AM UTC

Hello,

I cannot load your sample, as I get this error:

Severity Code Description Project File Line Suppression State
Error Your project is not referencing the "MonoAndroid,Version=v8.1" framework. Add a reference to "MonoAndroid,Version=v8.1" in the "frameworks" section of your project.json, and then re-run NuGet restore. App1.Android

I don't see a "project.json" file anywhere. Do you have any suggestions?

Thanks,

Dustin


TC Two Chain June 1, 2018 04:41 AM UTC

Hi Friends,

I appreciate the help you've provided, but I've come to the conclusion that Syncfusion Calendar still has many bugs. In UWP and Android, I find that the dates of the month and month names get mixed up after pressing the "current date" button several times.

I am attaching an example project. Please try toggling between month and year view, and hitting the "current date" button. You will find that the dates get mixed up.

Thank you,

Dustin


TC Two Chain June 1, 2018 04:48 AM UTC

Here is the file...

Attachment: CalendarTestAgain_36222067.zip


MS Mugundhan Saravanan Syncfusion Team June 1, 2018 01:04 PM UTC

Hi Justin,

Thanks for your update.

We have checked the reported issue. we are able to reproduce the reported issue “MoveToDate property is not working properly while moving from YearView mode to CurrentDate”. We have created a defect report for this.

This fix will be released in our upcoming volume 2 sp 1 release which will be rolled out by end of June month.

Regards,
Mugundhan S.


TC Two Chain June 1, 2018 07:04 PM UTC

Great, thanks! But just to be clear, the issue is not just switching from year to month view. The problem is actually more severe. Upon using the "current date" button 4-5 times, the actual days on the calendar no longer match with the months. For example, the first week of May no longer starts by showing April 29th (a Sunday). Rather, it shows May 1st as being a Sunday... Clearly this is a problem!

Thanks for your help.

Dustin


TC Two Chain June 1, 2018 08:04 PM UTC

For anyone else who runs into this problem, I think I finally have a work around that does not cause the dates/months to become mixed up.

In my "Current Date" method, I simply call a Navigation to a new Page. In the cs. file for the New Page, I put an immediate Navigation call back to the main calendar page. This essentially resets the calendar page, and is now making everything work nicely! It looks perfect on both UWP and Android.

Hopefully this helps someone else who runs into this issue.

Dustin


MS Mugundhan Saravanan Syncfusion Team June 4, 2018 04:31 AM UTC

Hi Justin,

Thanks for the workaround sample provided.

The Reported issue is mainly occur due to the MoveToDate property. If our issue is fixed means all our problems will clear. This issue is fixed in our upcoming Volume 2 sp1 release which will be rolled at end of this month.

Please let us know if you have any other concern.

Regards,
Mugundhan S.

Loader.
Up arrow icon