How to set min or max date limit in CakePHP form? - cakephp

In my current date form input, I have the parameter:
'maxYear' => date('Y')
This lets me limit the max year to this year, but I also need to limit the date selection so users cannot select a date in the future. Using maxYear only allows limiting the year, but I also need months and days.

That's not something you can do with the Form Helper (or the HTML form options even if you'd wrote them manually).
The problem:
If you limit the month to say, 1-7 (if we're currently in July), the user would be unable to select the previous year of any of those months.
The solution:
Use JavaScript onchange validation. When the field(s) change date, check the selected date against your required date range, and give notification if it fails. (see jQuery's .change() documentation if you're using jQuery)
(Then verify on the back-end, as well of course, as JavaScript can easily be manipulated)

Related

Google Data studio -Default filter on last month when data is at month level

I have a report with one data source in Google Data Studio. The data is at month level inside the BigQuery table YYYYMM (for example 202001). I have a filter that is set on the year-month dimension which works ok but I would like to add a default value which changes to last month(max(year_month)) available in the table.
Is this possible? I only found the option to hard-code the default selection but this can't be updated dynamically
as in this screen shot
Jaishree's suggestion
You can create an another field/column as same year-month and always keep the latest year-month value as "latest month" or any name you want. You can use logic like
when existing_column = max(year_month) then "latest month" else existing_column
Something like this
existing_column new_column
022020 latest month
012020 012020
122019 122019
112019 122019
You can pass this "latest month" value in the default selection option this option which is just below the dimension. But each time you upload new data you have to update this field like change the table suppose for next month you table should be like
existing_column new_column
032020 latest month
022020 022020
012020 012020
122019 122019
112019 122019
You can make auto update by scheduling queries as well in big query from where you are loading data to Google data studio.
It can be achieved by setting the Date Range (at the chart, report level, Date Range Control, etc) to Last Month.
First, a YYYYMMDD Date field needs to be created at the Data Source. This can be done using the CONCAT function to add a Day (the 15th is used in the formula) and then using the TODATE function (although in this case the TODATE function is not required, however, adding it as best practice):
TODATE(CONCAT(Date, "15"), "%Y%m%d", "%Y%m%d" )
Adding a link to post on the Google Forums (Nimantha; 10 Feb 2020) which also has a GIF to demonstrate the process above as well as adding the Date field at the Report Level.
You can do it by creating a new field where rows that belong to the current year-month are labeled as 'Current Month' while the others could use your preferred formatting (I'm using "%Y%m - %B %Y" as it allows me to sort report dates in a drop down list).
To do so, you need your date column and CURRENT_DATE() in the same format with the help of FORMAT_DATETIME(). Then, you can use CASE WHEN logic as follows:
CASE
WHEN FORMAT_DATETIME("%Y%m", MyDateColumn) != FORMAT_DATETIME("%Y%m", CURRENT_DATE())
THEN FORMAT_DATETIME("%Y%m - %B %Y", MyDateColumn)
ELSE 'Current Month'
END
Finally, you could use a drop down list control with the new field and use 'Current Month' as the default selection. The main advantage is that the code above will be evaluated every time data is refreshed so no extra automations needed.
Hope it works for you.

How to add two certain date limits on start date and enf date in any date range picker in react

I need to use a date range picker in which I need to implement the logic
Start date can be upto 6 months from today well end date will can be up to 6 months from a start date in a single date range selector
Well I played with different packages but I can able to set a limit on any one date.
Suggestions are appreciated
You can use react-calendar with moment, it supports some props two of which are minDate and maxDate.
Render two instances of react-calendar, pass minDate={moment().subtract(6, 'months')} and maxDate={moment()}.
Disable the second instance by default or render it only when user select a date in the first instance of the calendar.
Then pass minDate={dateSelectedInFirstInstance.add(1, 'day')} and maxDate={dateSelectedInFirstInstance.add(6, 'month')}.

Search between two dates with ISO8601 format

Using angularjs, dynamodb as DB here.
I have a form where user saves some data. I save my "CreateOn" date in my dynamo db as:
DateTime.UtcNow.ToString("o");
//This saves date in DB as:2018-08-21T12:58:08.7823906Z
Storing like this because dynamo db requires dates (string) to stored in ISO8601 format if you want to use between operator to search for date range.
Now I have a search filters on my page which is basically an angular calendar. When the user selects the date in the calendar( start and end date) I want to get the data back based on the selected date. Here I am using moment to pass the calendar selected date to my api call as:
moment(createdOn).toISOString()
Eg: If they select the Today's date in the calendar I pass the selected date
(Tue Aug 21 2018 00:00:00 GMT-0400 (Eastern Daylight Time)) to the above function
The result of passing this date to moment(createdOn).toISOString() is
2018-08-21T04:00:00.000Z
The search condition at dynamo db is:
conditions.Add(new ScanCondition("CreatedOn", ScanOperator.Between, startDate, endDate ));
If the user selects from the calendar the start date as "08-20-2018" (2018-08-20T04:00:00.000Z) and the end date is "08-21-2018"(2018-08-21T04:00:00.000Z), the code all the data created b/w these 2 dates.
Now the issue is if they select same start and end date then the code does not returns any data, I believe because the start and end date is "2018-08-21T04:00:00.000Z" and the time part of this is all 0000 etc.
My question is how can I convert the date from my calendar ie my end date to correctly reflect the the end time which they select. I havent used ISO8601 format before so not sure how can I do so.
Thanks
You don't need moment for this. You can zero out the time using a Date in the following way.
const date = new Date('2018-08-21T12:58:08.7823906Z')
date.setUTCHours(0)
date.setUTCMinutes(0)
date.setUTCSeconds(0)
date.setUTCMilliseconds(0)
Then you can simply use toISOString() to format the date.
date.toISOString()
// returns '2018-08-21T00:00:00.000Z'
If you don't want to zero out the time, and instead want to set some specific time, you can use a similar approach, just substitute the 0 with whatever time you want.
Some other things to note: DynamoDB doesn't require any specific formatting for dates. DynamoDB simply does a string or number comparison depending on what the field is defined as. You could store your dates in DynamoDB as integers or another string format if you feel that would be easier to work with.
Also, I'm not sure how your table is setup but make sure that your "CreateOn" field is the Range key and that you are using Query, not Scan. Using the Scan operation doesn't scale well.

ValueFilter for DateTime Attributes

I'm working with the Blog app and I see how to filter the Blog posts by year using the Visual Query Designer. I use the querystring value that has the year and in the ValueFilter and my properties are as follows:
Attribute: PublicationMoment
Value: [QueryString:year]-01-01 and [QueryString:year]-12-31
Operation: between
How would I get the posts from a specific month and year, if those values are passed via query string parameters. Because the months of the year have a varying number of days, I'm not sure how you would accomplish this in the Value field of the ValueFilter. Currently I'm passing the 2 digit month as the parameter.
I tried something like: [QueryString:year]-[Querystring:month]
Operation: contains
but the above operation doesn't really work because the datatype is a DateTime object.
I could do it in the razor view but I'm afraid that the paging datasource would have too many pages in it since it would be based on the larger subset of posts for the given year that was passed in the querystring parameter.
Is there any way to do this with the filter?
Basically dates are not perfectly handled yet, but there are a few ways to do it using the visual query:
Use the correct date in the query like between [QueryString:Start] and [QueryString:End] and calculate the correct dates there where you generate the links
Since your main problem with the "between" filter is actually that it would include the last day too, you could also use a two filters a >= first date and another < second date, so the first-date would be the year/month and day 1; the second one is year-month and day 1 as well
Last but not least: if you do it with razor and LINQ you shouldn't run into any performance issues - it's technically the same thing the pipeline does and it's been tested to perform well with tens of thousands of records.

Mobiscroll datetime, remove all validation

I'm prototyping this date picker with a client. They are finding it very confusing that you need to pick year first before other months and days become available for selection (which is fair enough).
We do date validation on the backened anyway, so is there anyway to remove the disabling of invalid dates so the user can choose anything they want immediately, instead of following the required pattern of year -> month -> day selections.
I couldn't find anything in the docs.
This was resolved by not including maxDate, even if it was null

Resources