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.
Related
I'd like to ask you for support. The yii2 Kartik datetimepicker extension is giving strange and random start date. After clicking the calendar the start date might be year 4678 or year 3599. Imagine scrolling this back to 2017 :) Have you ever faced similar issues. I have checked the forum and I was not able to find the answer.
Here is my code.
<?php
// Usage with model (with no default initial value)
echo $form->field($date, 'start_time')->widget(
DateTimePicker::className(),
[
'size'=>'md',
'type' => DateTimePicker::TYPE_COMPONENT_APPEND,
'convertFormat' => true,
'pluginOptions' => [
'todayHighlight' => true,
'todayBtn' => true,
'format' => 'dd-M-yyyy H:i',
'autoclose' => true,
'startDate'=> date('d-m-Y H:i', strtotime(time())),
],
])->label('Start Date');
?>
Here is the screen shot of the datetimepicker: https://ibb.co/fu5WFw
The second parameter of date() is a timestamp, so remove strtotime():
'startDate'=> date('d-m-Y H:i',time()),
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'
]
]);
?>
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?
i'm creating an API in Lumen and i need to create a method that will get dates from two colums on the same table and return any years that occur between those dates, returning them all as a single array.
So for instance, imagine a table column named start_date and another named end_date
start_date | end_date getAllYears() should return =>
[1983, 1984, 1985, 1986, 1987,
1999, 2000, 2001, 2002, 2003,
..., 2016]
1999-05-09 | 2002-04-03
1983-03-12 | 1987-09-23
2001-02-12 | 2016-11-27
Currently i have a method that manages to do this on other types of more specific queries, the major problem with this attempt, is that due to the sheer mass of SQL records that i'm retrieving, a method like this causes my request to time out every single time.
MY INEFFICIENT METHOD that makes little use of Lumen/Laravel
public function getAllYears(){
$dates = $this->model->select('data_ini', 'data_fim')->get();
$results = [];
foreach ($dates as $obj){
$carbonBegin = Carbon::createFromDate($obj->data_ini->year);
$carbonEnd = Carbon::createFromDate($obj->data_fim->year);
if($carbonEnd->year === 9999){
$carbonEnd->year = date('Y');
}
$carbonEnd->year++;
// Simple method that runs a DatePeriod method
$dateRange = $this->helper->createDateRange($carbonBegin, $carbonEnd);
$results = array_merge($results, $dateRange);
}
sort($results);
$cleanYears = array_unique($results);
if ($cleanYears == null)
return response()->json(['error' => true, 'errorCode' => '1008', 'message' => "No years found!"]);
else
return response()->json(['error' => false, 'years' => $cleanYears]);
}
So, the question is, how can i do this in a less expensive way so that my server doesn't time out on every request? Thank in advance for your help :)
NOTE: DB:raw is a no-go as my TL has forbidden me from using it anywhere on the API
Looks like you need the whereBetween:
$between = DB::table('theTable')->whereBetween('data_ini', ["str_to_date('2011-05-06','%Y-%m-%d')", "str_to_date('2011-05-06','%Y-%m-%d')"])->get();
With models:
$between = $this->model->whereBetween('data_ini', ["str_to_date('2011-05-06','%Y-%m-%d')", "str_to_date('2011-05-06','%Y-%m-%d')"])->get();
In the above, I am utilizing MySQL's built-in str_to_date
Hope this helps!
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