There are 7 input fields in my code but I want to use them for only one. Also there are multiple pages where this datepicker is used all done through a common datepicker directive. I don't want the other pages and input fields to get affected with this change. Here is my code :
beforeShowDay: function(date) {
var month = date.getMonth() + 1;
var year = date.getFullYear();
var day = date.getDate();
if (day < 10) {
day = '0' + day;
}
if (month < 10) {
month = '0' + month;
}
var newDate = month + "/" + day + "/" + year;
if (jQuery.inArray(newDate, highlight_date) != -1) {
//console.log(newDate);
return [true, "highlight"];
}
return [true];
}
I want to convert the commit date and time to time stamp which I get from my APIs.
But I don't know how to do this in angular?
Here is my controller code :
var commitDate = item.commitMetaData.commitDate;
var dat = new Date(commitDate);
But it says "Invalid Date"
PS: Thanks in advance
What you could do is generate the date from the values montValue , year, dayOfMonth
with plain Javascript you could just do
var d = new Date();
d.setMonth(commitDate.monthValue +1); //see explanation below
d.setDate(commitDate.dayOfMonth);
d.setYear(commitDate.year);
be careful the months start at 0 so January is actually 0 so in your example you would have to add +1
You can also create a filter for this
.filter('createDate', function ($filter) {
return function (input) {
if (input != null && input != undefined) {
var d = new Date();
d.setMonth(input.monthValue +1); //see explanation below
d.setDate(input.dayOfMonth);
d.setYear(input.year);
return d;
}
};
})
and call it like
var commitDate = item.commitMetaData.commitDate;
var dat = $filter('createDate')(commitDate);
reference JS Date
I am trying to modify a plugin, it is a calendar. When you press on the dates that are not part of the month (at the beginning and the end of the month) it changes to the next or previous month. I am trying to disable this, and I found what part of the code to change, but when I make the changes (or add a console.log message), nothing gets reflected when I execute ionic serve. One thing is, the calendar is written in AngularJS - while I am using Ionic, which uses Angular 2. The part of the code I am trying to change looks like this:
$scope.select = function (viewDate) {
console.log("in in in select &&&&&&&");
var selectedDate = viewDate.date,
events = viewDate.events,
views = scope.views,
dates,
r;
if (views) {
dates = views[scope.currentViewIndex].dates;
var currentCalendarDate = ctrl.currentCalendarDate;
var currentMonth = currentCalendarDate.getMonth();
var currentYear = currentCalendarDate.getFullYear();
var selectedMonth = selectedDate.getMonth();
var selectedYear = selectedDate.getFullYear();
var direction = 0;
if (currentYear === selectedYear) {
if (currentMonth !== selectedMonth) {
direction = currentMonth < selectedMonth ? 1 : -1;
}
} else {
direction = currentYear < selectedYear ? 1 : -1;
}
ctrl.currentCalendarDate = selectedDate;
if (direction === 0) {
if (ngModelCtrl) {
ngModelCtrl.$setViewValue(selectedDate);
}
var currentViewStartDate = ctrl.range.startTime,
oneDay = 86400000,
selectedDayDifference = Math.floor((selectedDate.getTime() - currentViewStartDate.getTime()) / oneDay);
for (r = 0; r < 42; r += 1) {
dates[r].selected = false;
}
if (selectedDayDifference >= 0 && selectedDayDifference < 42) {
dates[selectedDayDifference].selected = true;
scope.selectedDate = dates[selectedDayDifference];
}
} else {
console.log("is getting here &&^^%%$$");
//ctrl.moveOnSelected = true;
//ctrl.slideView(direction); <----- I AM COMMENTING THIS OUT TO STOP THE SLIDE!!!
}
...
At the bottom of the above code block, I made an arrow pointing to the two lines I am commenting out. I also added console.log statements, one at the beginning of the function, and one in the middle, and neither of them are output into the console (the above is the select function which happens when a date on the calendar is selected).
The code structure of the plugin is like this:
angular.module("ui.rCalendar.tpls", ["templates/rcalendar/calendar.html","templates/rcalendar/day.html","templates/rcalendar/displayEvent.html","templates/rcalendar/month.html","templates/rcalendar/monthviewDisplayEvent.html","templates/rcalendar/monthviewEventDetail.html","templates/rcalendar/week.html"]);
angular.module('ui.rCalendar', ['ui.rCalendar.tpls'])
.constant('calendarConfig', {
formatDay: 'dd',
formatDayHeader: 'EEE',
formatDayTitle: 'MMMM dd, yyyy',
formatWeekTitle: 'MMMM yyyy, Week w',
formatMonthTitle: 'MMMM yyyy',
formatWeekViewDayHeader: 'EEE d',
formatHourColumn: 'ha',
calendarMode: 'month',
showEventDetail: true,
startingDayMonth: 0,
startingDayWeek: 0,
allDayLabel: 'all day',
noEventsLabel: 'No Events',
eventSource: null,
queryMode: 'local',
step: 60,
autoSelect: true,
monthviewDisplayEventTemplateUrl: 'templates/rcalendar/monthviewDisplayEvent.html',
monthviewEventDetailTemplateUrl: 'templates/rcalendar/monthviewEventDetail.html',
weekviewAllDayEventTemplateUrl: 'templates/rcalendar/displayEvent.html',
weekviewNormalEventTemplateUrl: 'templates/rcalendar/displayEvent.html',
dayviewAllDayEventTemplateUrl: 'templates/rcalendar/displayEvent.html',
dayviewNormalEventTemplateUrl: 'templates/rcalendar/displayEvent.html'
})
.controller('ui.rCalendar.CalendarController'
...
.directive('monthview', ['dateFilter', function (dateFilter) {
THIS IS WHERE THE SELECT FUNCTION IS
...
This is an angularjs plugin in an Ionic app, remember it is built on Angular 2 not angularjs. Im not sure where the plugin javascript file gets loaded.
I was looking in the wrong package folder, I didn't realized I had installed a typescript version.
I want to use select "From" and "To" dates from datepicker and display all dates in between, in tabular form using angularjs.
Try this function to calculate no. of days. Hope it helps
function daysCalculator(date1, date2) {
var d1 = new Date(date1);
var d2 = new Date(date2);
var days = d1.getTime() - d2.getTime();
days = parseInt((((days / 1000) / 60) / 60) / 24)
return days;
}
Try using this.
function getDates(fromDate, toDate) {
var dateArray = [];
var nextDate = fromDate;
while (nextDate <= toDate) {
dateArray.push( nextDate );
nextDate.setDate(fromDate.getDate() + 1);
}
return dateArray;
}
I am trying to display the time difference between my {{trade.timer}} and the current time but coudn't succeed after many tries.
I am looking to make the $scope.gains[i].timer = vtime - "CURRENTTIME"
Here is my code:
$scope.updatetimerValue = function (timerValue){
$.each(timerValue, function(k, v) {
for (var i =0; i < $scope.gains.length ; i ++) {
if($scope.gains[i].orderid == v.orderid){
$scope.gains[i].timer = v.time;
}
}
});
}
<td>{{gain.timer | date: 'HH:mm'}}</td>
Any idea?
Note: v.time time format is yyyy-MM-dd HH:mm:ss
You can get date difference between two days with basic javascript.
var date = new Date('10/27/2014');
var currentDate = new Date();
var milisecondsDiff = date-currentDate;
var secondsDiff = miliseconds/1000;
var minutesDiff = seconds/60;
var hoursDiff = minutes/60;
var daysDiff = hours/24;
Also I suggest don't mix up AngularJS and JQuery.
And instead $.each use the angular.forEach
angular.forEach(values, function(value, key) {
///
});
or even better to use simple for loop, because it works faster.