Refresh the material calendar - angular-material

A problem with refresh the mat-calendar image. an initial current month of the calendar was displayed, but if I select any date of next month then the mat-calendar will not update with the next month.
expected result: select any date, mat calendar jump, or shows to the selected date
I try How to refresh mat-calendar after changing the background of highlighted dates also but still phasing with the above problem.

I also encountered this problem. Here is a solution (here I use moment.js. Date works just as well)
HTML
<mat-calendar #smallCalendar
[startAt]="smallCalendarStartAt"
[selected]="smallCalendarSelected">
</mat-calendar>
Typescript
// Small calendar properties
#ViewChild('smallCalendar', { static: false }) smallCalendar: MatCalendar<Date>;
smallCalendarStartAt: Date;
smallCalendarSelected: any;
// Refresh the small calendar
this.smallCalendarStartAt = new Date(moment().year(), +moment().format('MM'), +moment().format('DD'));
this.smallCalendarSelected = this.smallCalendarStartAt; // Update the selected day in mat-calendar
this.smallCalendar._goToDateInView(this.smallCalendarStartAt, 'month'); // Update the month in the mat-calendar
You can adapt the variable smallCalendarStartAt. Here, for the example, it will only switch to the next month with the day of the actual month
Here is a demo with the Date function: DEMO

Related

How to know if an event lasts multiple months

App Overview
I'm building an iOS app in Swift that shows a list of events. The data that I have for the events shows the name of the event, the start date (day, month, year), and the end date (day, month, year).
When the data is pulled from Firebase, I look at the start and end months and show the event for the appropriate month in a table view. The data is shown by month, so a user looking at May only sees May events and has to choose a different month to see events from that month.
Problem
Some events stretch for several months. For example, if an event begins in July and ends in September, my current implementation won't show the events during August.
Possible Solutions
I'm looking for an elegant way to programmatically check for this case and make sure it's shown in the correct month rather than manually manipulating the data to state the months in between.
If you have any suggestions, please let me know. Here is the solution that I'm considering:
Add a Bool data point saying if the event stretches several months or not. When events for a specific month are shown, check through all of these events to see if the month selected is greater than the start month of the event and less than the end month of the event.
This breaks down if the event stretches from one year into the next. I would need to add additional logic to handle that.
It sounds like you are simply comparing the displayed month to the event's start month and the event's end month.
Without any specifics your basic logic to determine whether to show an event in a displayed month is to see if the displayed month is greater to or equal to the event start month and less than or equal to the even end month.
In pseudo code that would essentially be:
if displayMonth >= event.startMonth && displayMonth <= event.endMonth {
// show event
}
Of course this needs to account for the year as well.
In addition to check month you also need to check year. For example:
// Check start date
if (displayYear == event.startYear && displayMonth >= event.startMonth) || displayYear > event.startYear {
// Check end date
if (displayYear == event.endYear && displayMonth <= event.endMonth) || displayYear < event.endYear {
// show event
}
}
Let me know if you need more information or description of this code
comparing dates will work for you.
compare current date with starting date and ending date.
current date should be greater than starting date and less than ending date.
Here is code snippests for Date comparision
if currentDate.compare(startingDate) == .OrderedAscending && currentDate.compare(endingDate) == . OrderedDescending {
//Here will your event code will come.
}

Google Sheets: IF and Date formula not working

I'm calculating annual holiday accrual.
All holiday resets at the start of the calendar year.
If a staff member started after 01.01.2017 they will have a lower holiday entitlement for the year.
I'm trying to create a formula which says:
If this cell's date is after 01.01.2017 return that cells date. Otherwise, set it at 01.01.2017.
(so basically, I don't care when they started if it was before 01 Jan 2017 because all my following calculations will be based off the first day of the year)
Here it is:
=if(T21<date(1,1,2017),T21,"01/01/2017")
No matter what is in the cell, it is returning 01/01/2017.If I change the < to > it returns cell T21 in all cases.
Any ideas?
Thanks
You have the DATE() values mixed up. Try:
=if(T21<date(2017,1,1),T21,"01/01/2017")
DATE() is year, month, day
Also, you may want to use DATEVALUE() on the FALSE value to force the returned item to a date:
=if(T21<date(2017,1,1),T21,DATEVALUE("01/01/2017"))
"01.01.2017" is not a valid date in Google docs. You need to change . to /.
=DATEVALUE(SUBSTITUTE(T21,".","/"))
=IF(DATEVALUE(SUBSTITUTE(T21,".","/"))<DATEVALUE(date(2017,1,1)),T21,"01/01/2017")

Set start and end date to current month Google Anaytics API

I'm setting up Google Sheet report using the Google Analytics app to generate a custom report, I've spent days searching for info on the subject all over the web for an answer to set current month for the report.
I can set start and end date with no problem, but I want the automated reports to be able to reset to the current month without me having to update the start and end date every month.
To achieve this, use the below:
For End Date, use
today
or, to make your report upto the previous day:
yesterday
For the start date, use the formula below:
=CONCATENATE(YEAR(today()),"-",
IF(LEN(MONTH(TODAY()))=1,CONCATENATE(0,MONTH(TODAY())),MONTH(TODAY())),
"-01" )
The formula will concatenate the current year, current month, and 01.
Another way to approach this problem is through using EOMONTH, for example to get the first day of this month:
=EOMONTH(today(), -1)+1

Knowing if the user wants the week to begin on a Sunday or Monday

There is a calendar setting in iOS that allows the user to change on what day the week-based calendar begins. I display a calendar in my app and want to be able to leverage this setting so the layout of my weekday columns matches those of the first party Calendar app.
Is there a way to do this? I've tried tapping the .firstWeekday property of NSCalendar but it always returns 1, regardless of setting.
Change your phone's region and try this:
let firstWeekday = Locale.current.calendar.firstWeekday
print(firstWeekday)
The console prints 1 when the region is en_US and 2 for en_FR (France), which correspond to Sunday and Monday respectively.

DatePicker include Year

I have dataPicker in my app implemented. But it only shows month,day,hour. How could I able to add year in the date picker. Any idea?
datePicker.datePickerMode = UIDatePickerModeDate;
UIDatePickerModeDate
The date picker displays months, days of the month, and years. The exact order of these items depends on the locale setting. An example
of this mode is [ November | 15 | 2007 ].
Available in iOS 2.0 and later.
Declared in UIDatePicker.h.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDatePicker_Class/Reference/UIDatePicker.html
Also you can change from storyboard set Mode: (Refer to screenshot)
If you want to add month, date, year as well as time, add one picker that implements the dates only using (UIDatePickerModeDate) and an additional one for the time (UIDatePickerModeTime).

Resources