danheron / Heron.MudCalendar

Calendar component for MudBlazor
MIT License
151 stars 30 forks source link

Current Time Marker #79

Closed APusch-Tenno closed 8 months ago

APusch-Tenno commented 8 months ago

hi, since there are not many (paid and free) alternatives out there for a scheduler in MudBlazor and this one is fitting my needs quite well, I really want to make this work.

unfortunately I've come across a few issues.

one of these is that the marker for the current time is not displaying at the correct spot. with half hour view the marker is always jumping to the next half hour. in 15 minute view it is always between the grid lines and for each quarter hour it jumps half a grid field ahead and then stays there until the time hits the next quarter hour.

I have another major issue, but I will open a new ticket for that.

thanks for creating this scheduler/calendar and I hope these issues can get fixed.

danheron commented 8 months ago

I can't recreate this problem - it always looks correct to me.

Do you see this problem in the example on the docs page? If yes, then what browser are you using?

APusch-Tenno commented 8 months ago

yes, in the docs page it is always jumping ahead between the lines, no matter what setting I use. for some reason in my project it jumps only on the lines, but still shows the incorrect time: grafik

I tested the doc page with different browsers (Edge, Chrome, Firefox), time was 8:40 am: grafik

could this be a localization issue? I'm in germany. but I don't see why my project shows something different, while on the same machine (separate VM) it shows the same behavior on the doc page. either way neither shows the correct time.

danheron commented 8 months ago

Yes, it is a localisation issue. I will fix that.

APusch-Tenno commented 8 months ago

thanks

APusch-Tenno commented 8 months ago

I have inserted the fixed code in my project, but unfortunately the time is still not correctly showing, although now the marker seems to move with each minute.

Actual time here is 11:24: grafik grafik

It seems so be shifted by about 10 minutes now.

Sorry for bothering.

danheron commented 7 months ago

Do you still have this problem? In the example you sent me it looks correct. Do you have the problem in all browsers?

APusch-Tenno commented 7 months ago

Yes, the problem is still there, but as written before, the marker now moves with each minute.

grafik actual time was 16:20 (I think it is showing 16:35, so it is shifted 15 minutes with each minute)

tested in Firefox, Chrome and Edge, same result

danheron commented 7 months ago

That's very strange I can't replicate this problem. Could you try debugging it yourself and see if you can find the problem.

APusch-Tenno commented 7 months ago

As you might have figured out, I'm quite new to Blazor, but I managed to figure out, that the shift is always exactly half of the set interval, so +5 when in 10 minute interval and +30 when in 60 minute interval.

For now I fixed my indicator by changing TimelinePosition() in DayWeekViewBase.razor.cs from this var minutes = (int)Math.Floor(DateTime.Now.Subtract(DateTime.Today).TotalMinutes) - (TimelineRow() * (int)Calendar.DayTimeInterval); to this var minutes = DateTime.Now.Subtract(DateTime.Today).TotalMinutes - (TimelineRow() * (int)Calendar.DayTimeInterval) - (int)Calendar.DayTimeInterval / 2;

But obviously this is not a general fix. I don't see why the localization is changing the outcome, since DateTime.Now already gives the local date and time. I tried changing DateTime.Today to DateTime.Today.ToLocalTime(), which again puts the indicator right in the middle of the interval lines.

Maybe you can figure out more with this information. If not I will leave it like that, because this page is not supposed to be used outside this timezone.

danheron commented 7 months ago

Where do you get this code from? The code in TimelinePosition() has never included Math.Floor().

The localization changes the output because some cultures use , as a decimal point and some cultures use . The fix I applied was to use TimelinePosition().ToInvariantString() in the StyleBuilder() function.

APusch-Tenno commented 7 months ago

Ah, sorry... I was experimenting with rounding the values, because I assumed it had to do with . vs. , as a decimal indicator, due to the whole localization issue.

I have inserted your fix, as stated before, which at least made the indicator move.

I meant so say: I changed var minutes = DateTime.Now.Subtract(DateTime.Today).TotalMinutes - (TimelineRow() * (int)Calendar.DayTimeInterval); to var minutes = DateTime.Now.Subtract(DateTime.Today).TotalMinutes - (TimelineRow() * (int)Calendar.DayTimeInterval) - (int)Calendar.DayTimeInterval / 2;

so subtracting half of the interval This doesn't fix the origin of the problem, but for now does the job for me.