1

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
Community
  • 1
  • 1
FPcond
  • 581
  • 2
  • 7
  • 21

2 Answers2

1

It is looks for me you have +5 hours in time zone.

var WOD = new Date();
    WOD.setHours(0,0,0,0);// Sun Jan 04 2015 00:00:00 GMT-0600 (CST)

var WOD = new Date();
    WOD.setUTCHours(0,0,0,0);// Sat Jan 03 2015 18:00:00 GMT-0600 (CST)

All the difference in the settings of YOUR MACHINE. Check the settings of "Time Zone".

Ruben Kazumov
  • 3,803
  • 2
  • 26
  • 39
0

Please see demo below;

var app = angular.module('app', []);

app.controller('firstCtrl', function($scope) {

  $scope.date = new Date();

  $scope.date.setHours(0, 0, 0, 0);

});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<body ng-app="app">
  <div ng-controller="firstCtrl">
    {{date}}
  </div>
</body>
sylwester
  • 16,498
  • 1
  • 25
  • 33
  • @FPcond it looks like something different changing your date can you please show us all your controller code ? – sylwester Jan 04 '15 at 20:43
  • yup ill edit question 1 sec. I would use plunker but ui-calendar has a lot of sub dependencies. – FPcond Jan 04 '15 at 20:44
  • you can see my current work around was setting WOD to null and using an if statement to have the user select a date – FPcond Jan 04 '15 at 20:46
  • @FPcond ... that's weird please look here http://jsbin.com/lagowicika/1/edit?html,js,output I've got 2015-01-04T00:00:00.000Z – sylwester Jan 04 '15 at 20:58
  • I have the jsbin up right now and its still 2015-01-04T05:00:00.000Z http://postimg.org/image/p1qef8j7l/ – FPcond Jan 04 '15 at 21:03
  • @FPcond that's even worse please have a look here http://postimg.org/image/xzf71la31/ check it other browser – sylwester Jan 04 '15 at 21:07