formatting events date and time on fullcalendar - fullcalendar

Supposing am getting the dates for an event from a database in what format should my event date be am thinking.
start: 2012-03-29, 08:00am,
end: 2012-03-30, 08:00am,
allday: false,
it does not recognize the end date and the time for the event
Am I doing the wrong thing?

I use the following format and it works for me:
mm/dd/yyyy hh:mm tt
e.g.
03/15/2012 05:10 AM
Also make sure that in your JSon you have allDay as a boolean and not as a string
"allDay"= "false", // this is wrong. In this case you won't see any events on your calendar
"allDay"= false, // This is correct
Hope this helps

Related

How to check if a string denotes a 24 hour valid time format using momentJS?

The code:-
moment(moment("2022-12-12").format("YYYY-MM-DD"), "YYYY-MM-DD", true).isValid()
returns true as 2022-12-12 is a valid date in YYYY-MM-DD format.
Using the same logic, I tried to check if var timeString = "16:00:00" is a valid time or not.
However, the following code:-
moment(moment("16:00:00").format("HH:mm:ss"), "HH:mm:ss", true).isValid()
always gives me false.
What am I doing wrong?
It's always giving true as you are formatting to that particular type first than checking if its valid which is why its always true.
I think you want something like this.
function isTimeFormat(time) {
return moment(time, 'HH:mm:ss', true).isValid();
}

Moment.js, FullCalendar.js datetime comparisons with timezone offsets

I'm confused.
I have a textbox that is populated with a date and time (string) such as '09/07/2021 10:30'.
I convert this string to a moment like so:
var suggestedDateObj = moment(suggestedDate, 'DD/MM/YYYY HH:mm');
I then want to check if this date and time is in between time slots in a fullcalendar.js event object. I do this like so:
var startDateObj = moment(value.start);
var endDateObj = moment(value.end);
if (suggestedDateObj.isBetween(startDateObj, endDateObj)) {}
However...it isn't working. And it's due to timezone offset (i think).
suggestedDateObj returns a value with a UTC offset of +0100 (British Summer Time)
However my calendar event objects return a date with a UTC offset of +0000. So when i check if '09/07/2021 10:30 +0100' is in between '09/07/2021 10:30 +0000' and '09/07/2021 11:30 +0000' it doesn't work!
I guess my question is really either:
How can I create my suggestedDateObj moment with a timezone offset of zero? OR
How can i tell fullcallendar events that the time it is displaying is actually BST (+0100)? At the moment I don't specify the 'Timezone' parameter.
Thanks.
UPDATE
Hmm....this might work....although it feels a bit clunky:
var tmoment1 = moment(suggestedDate, 'DD/MM/YYYY HH:mm');
//create default date with specific timezone offset of zero
var suggestedDateObj = moment().utcOffset(0);
//set the date and time
suggestedDateObj.set({
day: tmoment1.day(),
month: tmoment1.month(),
year: tmoment1.year(),
hour: tmoment1.hour(),
minute: tmoment1.minute(),
second: 0
});
You can generate suggestedDateObj in utc like that:
var suggestedDateObj = moment.utc(suggestedDate, 'DD/MM/YYYY HH:mm');`
For the .isBetween() I suggest you to use the square bracket like forth parameter, like documentation says.
if (suggestedDateObj.isBetween(startDateObj, endDateObj, undefined, '[]'))
The square brackets indicate that the check must include the dates of the limiter

datesDisabled Bootstrap-DatePicker

There are plenty of questions on this but none of them seem to have worked for me.
I will eventually have an array of dates being passed in for multiple days over different months.
I'm using this version of the bootstrap datepicker
https://bootstrap-datepicker.readthedocs.io/en/latest/
looking over the docs, a simple array of dates for'disabledDates' should be all it needs to get these working, but I'll be damned if it accepts it.
Any ideas as to why it doesn't work?
var disabledDates = ['28/3/2018','22/3/2018'];
$('.datepicker').datepicker({
format: 'DD/MM/YYYY',
maxViewMode: 1,
todayBtn: "linked",
clearBtn: true,
multidate: true,
daysOfWeekDisabled: "0,6",
datesDisabled: disabledDates
})
In disabledDates variable you used dates like '28/3/2018' and '22/3/2018'. According to the doc these dates are in this format d/m/yyyy or dd/m/yyyy.
But, inside datepicker() function you have declared the date format as DD/MM/YYYY.
Try to change the date format format: 'DD/MM/YYYY', to format: 'd/m/yyyy', or format: 'dd/m/yyyy',

Link to add Google Calendar event loads incorrect time

So I'm trying to create an "Add Event to Calendar" link with this format:
https://www.google.com/calendar/render?action=TEMPLATE&text=My+Big+Party&dates=20160320T140000Z/20160320T180000Z&details=It+will+be+crazy&location=123+Granville+St+Vancouver+BC&sf=true&output=xml
And it mostly works, but the time is wrong. I'm in Vancouver (same time zone as the event) and it wants to save the event from 7am to 11am (it should be 2pm to 6pm).
What am I doing wrong?
EDIT:
I'm trying to convert my times to UTC but I'm getting "Call to a member function setTimeZone() on a non-object":
function ls_convert_time($dt, $tz1, $df1, $tz2, $df2) {
// create DateTime object
$d = DateTime::createFromFormat($df1, $dt, new DateTimeZone($tz1));
// convert timezone
$d->setTimeZone(new DateTimeZone($tz2));
// convert dateformat
return $d->format($df2);
}
$new_start_time = ls_convert_time($start_time, $time_zone, 'HHmmss', 'UTC', 'HHmmss');
$new_end_time = ls_convert_time($end_time, $time_zone, 'HHmmss', 'UTC', 'HHmmss');
Take the Z out of the time and don´t use ctz. That´ll work for you and it[ll show the right time for the right zones

Gridview time format

I have a BoundField that's using a Datafield linked to a datetime type variable. I want to display only the time, not the date. How do you show the time in 24-hour format or in AM/PM format, depending on a boolean in the code behind.
Thanks.
Try something like this:
<%# Eval("AmPmMode").ToString().Equals("true")) ?
String.Format("{0:hh}:{0:mm} {tt}", Eval("date")) :
String.Format("{0:HH}:{0:mm}", Eval("date")) %>
You can format your date for AM PM mode or for 24h mode. tt is the AM/PM designator.
AmPmMode is flag from you DB, should be true or false, but you could change it to 0 or 1.
See also:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

Resources