I am using ui-calendar and I am trying to pass events without a time. Right now I get my date and time like this.
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var WOD = new Date(y,m,d);
now I also have a function that changes WOD to the day that is selected in the month view of the calendar like this.
$scope.alertOnDayClick = function(d){
WOD = d;
};
If I click on a day (Jan 22 2015 for this example) WOD = "2015-01-22T00:00:00.000Z"
<--This is what I want and works well.
But if I don't select a day by default WOD = "2015-01-04T05:00:00.000Z"
I want to make it so that my default date contains the time T00:00:00.000Z.
I have tried
var WOD = new Date(y,m,d,0,0,0,0)
var WOD = date.UTF(y,m,d)
var WOD = date.UTF(y,m,d,0,0,0,0)
I also tried setting the default time to null I read this question Dealing with DateTime format for international application But I don't know if this is applicable and honestly I didn't fully understand how I would implement it
All help is appreciated.
UPDATE:
After reading What is the best way to initialize a JavaScript Date to midnight?
I tried
var WOD = new Date();
WOD.setHours(0,0,0,0);
But it still returns "2015-01-04T05:00:00.000Z"
Which then makes the event stored on Jan 4 at 12am
UPDATE:
I tried:
$scope.WOD = new Date();
$scope.WOD.setHours(0, 0, 0, 0);
$scope.dangerMessage = ($scope.WOD);
{{dangerMessage}} = "2015-01-04T05:00:00.000Z"
UPDATE W/ Full controller
var myAppModule = angular.module('MyApp', ['ui.calendar']);
myAppModule.controller('MyController', function($scope,$compile,uiCalendarConfig) {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$scope.WOD = new Date();
$scope.WOD.setHours(0, 0, 0, 0);
$scope.events = [
{title: 'All Day Event', start: new Date(y, m, 1)},
{title: 'Long Event', start: new Date(y, m, d), end: new Date(y, m, d)},
{id: 999, title: 'Repeating Event', start: new Date(y, m, d - 3, 16, 0), allDay: false},
{id: 999, title: 'Repeating Event', start: new Date(y, m, d + 4, 16, 0), allDay: false},
{
title: 'Birthday Party',
start: new Date(y, m, d + 1, 19, 0),
end: new Date(y, m, d + 1, 22, 30),
allDay: false
},
{title: 'Click for Google', start: new Date(y, m, 28), end: new Date(y, m, 29), url: 'http://google.com/'}
];
$scope.addEvent = function() {
if($scope.WOD === ''){
$scope.dangerMessage = ('Please Choose a Date');
}else{
$scope.events.push({
title: 'Open Sesame',
start: $scope.WOD,
end: $scope.WOD,
className: ['openSesame']
});
}
$scope.dangerMessage = ($scope.WOD);
};
$scope.alertOnEventClick = function( date ){
$scope.alertMessage = (date.title + ' was clicked ');
};
$scope.alertOnDayClick = function(d){
uiCalendarConfig.calendars['CalDayView'].fullCalendar('gotoDate', d);
WOD = d;
$scope.dangerMessage = (WOD);
};
/* remove event */
$scope.remove = function(index) {
$scope.events.splice(index,1);
};
/* config object */
$scope.uiDayConfig = {
calendar:{
height: 450,
editable: true,
header:{
left: 'today',
center: 'title',
right: 'prev,next'
},
timeFormat: '',
defaultView: 'basicDay',
defaultDate: new Date(),
eventDrop: $scope.alertOnDrop,
eventResize: $scope.alertOnResize,
eventClick: $scope.alertOnEventClick,
eventRender: $scope.eventRender
}
};
$scope.uiMonthConfig = {
calendar:{
height: 450,
editable: true,
header:{
left: 'prev,next',
center: 'title',
right: 'basicWeek'
},
dayClick: $scope.alertOnDayClick,
//eventDrop: $scope.alertOnDrop,
//eventResize: $scope.alertOnResize,
eventClick: $scope.alertOnEventClick
//eventRender: $scope.eventRender
}
};
$scope.eventSources = [$scope.events];
});//END MYCONTROLLER