how to resolve this interpolate error - angularjs

My Code is working fine but console shows the error for interpolate:
Error: [$interpolate:interr] Can't interpolate: {{expression}} {{date_expression | date : 'mediumDate'}} TypeError: date is undefined
{{expression}}
giving its right result and
{{date_expression | date :'mediumDate' }}
shows correct date in the right format Sep 3, 2015
This is the method which I am using:-
$scope.formatDate = function(date){
// var date = '030915',
day = date.substring(0, 2),
month = date.substring(2, 4),
year = date.substring(4, 6);
var dateOut = new Date('20' + year, month - 1, day);
return dateOut;
}
<div> {{item.origin}} {{formatDate(item.departuredate) | date : 'mediumDate' }}
</div>
here item.departuredate = "030915".
It is working fine but shows interpolate error.
Thanks
but I want to remove this error from the console. Someone could help me to resolve this problem.
Thankyou

Related

convert string Time to 12 hour format in React

I have passed the showtime as a parameter and I want to convert it to 12 hour format
following is my code
componentDidMount() {
let movieInfo = queryString.parse(this.props.location.search)
console.log(movieInfo.movieid)
this.setState(movieInfo)
console.log(movieInfo.name)
movieData = movieInfo
}
my URL : is http://localhost:3000/#/seat-booking?showtimes=2130
I want to convert the "2130" into 9.30 PM. Any suggestions??
Something like this, maybe.
This assumes s is either 3 characters (930) or 4 characters (2130) but does absolutely no other validation.
function militaryTimeTo12Hour(s) {
if(s.length == 3) s = `0${s}`; // 930 -> 0930
const hour = parseInt(s.substring(0, 2), 10);
const min = parseInt(s.substring(2, 4), 10);
if(hour < 12) return `${hour % 12}:${min} AM`;
return `${hour % 12 || 12}:${min} PM`;
}
> militaryTimeTo12Hour("1230")
"12:30 PM"
> militaryTimeTo12Hour("2130")
"9:30 PM"
> militaryTimeTo12Hour("330")
"3:30 AM"
> militaryTimeTo12Hour("zquz")
"12:NaN PM"
> militaryTimeTo12Hour("3314")
"9:14 PM"
> militaryTimeTo12Hour("-799")
"-7:99 AM"
you can use moment.js
moment('2130', 'hhmm').format('h:mm A')

Getting only "today and yseterday" from ngx-moment in angular 9

I'm using ngx-moment pipe to display my date
it's really helpful and very useful
But I want to display the date from today and tomorrow and then the calendar date like that
if the date today then "Today and 00:00pm", it tomorrow then "Yesterday at 00:00pm",
Then if the day after tomorrow I need to show the calendar date "13/9/2020"
here is the code
date:'2020-09-13T00:00:00' ;
<div>Last updated: {{date| amTimeAgo}}</div>
I solved it
moment.updateLocale('en', {
calendar : {
lastDay : '[Yesterday] LT',
sameDay : '[Today] LT',
nextDay : 'LL',
lastWeek : 'LL',
nextWeek : 'LL',
sameElse : 'LL'
}
});

Change date format in angularjs

I am getting date format like this /Date(1497683045200)/. I want to convert it as dd/MM/yyyy. I tried this
<td>{{data.From | date:'MM/dd/yyyy' }}</td>
But format is not changed.Any suggestion?
create a custom filter like this
.filter('jsonDate',function(){
return function(date){
return new Date(date.match(/\d+/)[0] * 1);
}
})
call it like this
<td>{{data.From | jsonDate | date:'MM/dd/yyyy'}}</td>
try this
formatDate(date) {
let d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
return [ month, day, year].join('/');
}
Call that custom method on HTML
<td>{{formatDate(data.From)}}</td>

Find difference between 2 dates with AngularJS

I get 2 dates from MySQL something like this:
Start: 2015-11-01 22:56:59 End: 2015-11-03 00:00:00
Also I get dates from object array; here is what one object looks like:
Array[5]
0: Object
$$hashKey: "object:9"
created_at: "2015-10-23 03:36:11"
expiration_date: "2015-11-03 00:00:00"
id: 1
name: "TEST PROJECT"
I need to find how many days left with AngularJS...
Its simple. Use the function as:
$scope.calcDiff = function(firstDate, secondDate){
var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
var diffDays = Math.round(Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay)));
}
Consider using moment.js for all your javascript date and time manipulations.
With the moment library it is as easy as:
moment(date1).diff(moment(date2), 'days')
You just need to write a js function, that do all calculation instead of you.
<label>{{diffDate(date1, date2) }} </label>
$scope.diffDate = function(date1, date2){
var dateOut1 = new Date(date1); // it will work if date1 is in ISO format
var dateOut2 = new Date(date2);
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
alert(diffDays);
return dateOut;
};
If your data is not in ISO format, you have to set it explicitly.
var dateString = "2015-01-16 22:15:00";
var date = Date.parse(dateString, "yyyy-MM-dd HH:mm:ss");
You can use amDifference filter. Don't forget to inject $filter
let dif = $filter('amDifference')(date1, date2, 'days');

Cannot find function createEvent in object

I have no idea why I am getting this error... All of the other code in this script is commented out...
Any help would be appreciated!
error message: TypeError: Cannot find function createEvent in object . (line 16, file "Code")
function createEvent(test)
{
var cal = CalendarApp.getCalendarsByName(test);
var title = 'Script Demo Event';
var start = new Date("April 5, 2013 08:00:00 PDT");
var end = new Date("April 5, 2013 10:00:00 PDT");
var desc = "Created using Google Apps Script";
var loc = "Script Center";
var event = cal.createEvent(title, start, end, {description:desc, location:loc});
};
(friend figured it out)
These two do not play well together....
createEvent AND getCalendarsByName
createEvent must use getCalendarsByID

Resources