DateType and various formats - html

I have DateType. For example for saving foundation of some band to our database.
->add('founded', DateType::class, [
'label' => 'Founded',
'widget' => 'single_text',
'required' => false
])
There is unknown full date sometimes. There can be only a year and month known, or just a year without the day and month. But if I fill an incomplete date to this HTML5 input, nothing is saved and I have HTML5 error.
How is it possible to parse full date, year and month or just year with DateType and HTML5 input? Or is there any other alternative and clean solution?

Related

Date formatting on Kendo Grid Group Header

I need to Group a Kendo Grid for every Month data. i am getting date in ISO format as given below.
2020-03-02T00:00:00
This is the column binding and data source grouping
column binding.
columns.Bound(z => z.MonthDisplay).Title("").Hidden(true).Format("{0:MMMM yyyy}");
data source binding with grouping
.DataSource(dataSource => dataSource
.PageSize(10)
.Group(groups => groups.AddDescending(t => t.MonthDisplay))
.Read(read => read.Action("AllData", "Common"))
)
The grouping is working properly. But my problem is the group heading is not formatting in MMMM yyyy format. It is showing as Month: 2020-03-02T00:00:00. I need to display header as Month: March 2020
I found the solution for this. I added a GroupHeaderTemplate as given below:
.columns.Bound(z => z.MonthDisplay).Title("").Hidden(true).ClientGroupHeaderTemplate("#= kendo.toString(kendo.parseDate(value.split('T')[0]), 'MMMM yyyy') #");

Yii2 Boostrap period picker

I'm using Yii2 and I would like to have the following things:
A dropdown with "ranges" as items (week, full week, week-end, etc.) (done)
A RangePicker that based on the chosen range will:
allow only some days as the startDate (ex: week = mondays; week-end = saturdays)
will automatically select the end date based on the start date (ex: week: monday to friday; full week: monday to sunday; week-end: saturday to sunday, etc.)
For the dropdown, it's fine. But for the DateRangePicker, I started using Krajee DateRangePicker and
I do not find a callback for "onStartDateSelected" (I only saw a callback that is called when the range is selected, but not for individual start date or end date)
I do not see a "setStopDate" function
I do not see how to dynamically change the available days of weeks
I see that we can have a set of predefined periods like "last 7 days", "this month", etc. But this is not what I want. I want the user be able to select the start date but automatically calculate the end date based on what the user has set.
(I'm new in web dev, so please if you find anything that I could improve in my question, don't be afraid to share it)
You can use the following to accomplish the task:
Use the following library:
use kartik\date\DatePicker;
Use the following code in view:
<?php
$layout3 = '<span class="input-group-addon">From Date</span>
{input1}
<span class="input-group-addon">To Date</span>
{input2}
<span class="input-group-addon kv-date-remove">
<i class="glyphicon glyphicon-remove"></i>
</span>';
$previousDay = strtotime('-7 day', strtotime(date('d-M-Y'))); //Set as per your requirement[![enter image description here][1]][1]
echo DatePicker::widget([
'type' => DatePicker::TYPE_RANGE,
'name' => 'startDate',
'value' => date('d-M-Y', $previousDay),
'name2' => 'endDate',
'value2' => date('d-M-Y'),
'separator' => '<i class="glyphicon glyphicon-resize-horizontal"></i>',
'layout' => $layout3,
'pluginOptions' => [
'autoclose' => true,
'format' => 'dd-M-yyyy'
]
]);
?>

Use DB expression or PHP datetime as timestamp?

I have a timestamp behavior (yii2) that looks like this (taken from user guide example)...
public function behaviors()
{
return [
'timestamp' => [
'class' => TimestampBehavior::className(),
'value' => new Expression('NOW()'),
],
];
}
But is it not better to use a PHP DateTime expression like...
'value' => (new /DateTime('NOW'))->format('Y-m-d H:i:s')
Seems to me like it would be better to work with one clock rather than possibly two (in case the database server is separate and time not in sync, which is not unlikely.) Especially if I'm using DateTime in my code to check other conditions.
Which approach is better and why?
Expression class created a DBMS function inside the SQL query, it works no matter which date type (or format, it is possible to force the date format in some DBMS) you have in your column. If you change the value of a behavior you should take care the format and type of your column does match, otherwise some time you would get an error.

Cakephp 3.0 I would like to include a Year input field with a drop down, but it is inputing as an array

I have a Year field in a form and I am using FormHelper.
echo $this->Form->input('year', [
'type' => 'year',
'minYear' => date('Y')-10,
'maxYear' => date('Y')
]);
The table file validator looks like:
->add('year', 'valid', ['rule' => 'numeric'])
->allowEmpty('year')
I have a very similar input in another app that seems to work fine. I set the MySql column to int(5) to match what I had working elsewhere.
Checking debugkit it shows the "year" input as an array while the other inputs are strings. If I remove the validation rule it throws an illegal array to string conversion, so I assume this is where the error is.
Any help is greatly appreciated.
I have just tested with your above code and it is working fine for me. Try to delete the cache and check it once more.
Creates a select element populated with the years from minYear to maxYear. Additionally, HTML attributes may be supplied in $options. If $options['empty'] is false, the select will not include an empty option:
empty - If true, the empty select option is shown. If a string, that
string is displayed as the empty element.
orderYear - Ordering of
year values in select options. Possible values ‘asc’, ‘desc’. Default
‘desc’ value The selected value of the input.
maxYear The max year to
appear in the select element.
minYear The min year to appear in the
select element.
Try this one:
<?php
echo $this->Form->year('exp_date', [
'minYear' => date('Y')-10,
'maxYear' => date('Y'),
'id' => 'cc-year',
'class' => 'form-control',
'empty' => false,
'orderYear' => 'asc'
]);
?>
Official Documentation: CookBook - Creating Year Inputs

FullCalendar not displaying event times - fed from CFC

I've seen this asked (and answered) a number of times, but thus far none of the solutions is working for me.
I have a cfc that returns json data to an instance of FullCalendar.
The returned data looks like this:
[{"id":2,"title":"Test Event One","start":"February, 17 2011 09:30:00","end":"February, 17 2010 10:30:00","allday":false}]
The event is showing on the right day in all the calendar views - but is showing up in the all day section.
I'm invoking the calendar like this:
$('#calendar').fullCalendar({
editable: true,
events:'getEvents.cfc?method=getEvents&returnformat=json',
header: {
right: '',
center: 'prev,next today',
left: 'agendaDay,agendaWeek,month,'
}
I'd really appreciate any help with this - Thanks
This is what I did on the jason-event.php and it worked
<?php
$year = date('Y');
$month = date('m');
echo json_encode(array(
//May
array(
'id' => 1,
'title' => 'Cardio-Kick Boxing and Adult Kung Fu ONLY',
'start' => '2011-05-28 9:30:00',
'end' => '2011-05-28 12:00:00',
'allDay' => false,
'url' => 'http://maxfit.us/'
),
));
?>
It doesn't appear that you're returning the date in the format the fullCalendar object expects. Looking at the Event Object documentation, you need to return the dates in the following formats:
start: Date A JavaScript Date object
indicating the date/time an event
begins.
When specifying Event Objects for
events or eventSources, you may
specify a string in IETF format (ex:
"Wed, 18 Oct 2009 13:00:00 EST"), a
string in ISO8601 format (ex:
"2009-11-05T13:15:30Z") or a UNIX
timestamp.