$cookieStore expiration time not working in angularjs - angularjs

I have used $cookieStore in angularjs with expiration time but expiration time is not working.
Look at this code...
var today = new Date();
var expiresValue = new Date(today);
//Set 'expires' option in (365 x 24 x 60 x 60) = 31536000 seconds = 1 year
expiresValue.setSeconds(today.getSeconds() + 31536000);
// Setting a cookie
$cookieStore.put('STYPE', response.data.type, {'expires' : expiresValue});
How can i set expiration time in angularjs.

$cookieStore is depricated. Instead of using $cookieStore use $cookies
https://docs.angularjs.org/api/ngCookies/service/$cookies
$cookies.put('STYPE', response.data.type, {expires : expiresValue});

Related

Countdown Timer in Angular using $Interval()

I am implementing a function to have a countdown in Angular form current time - existing time in future. If the time has elapsed then display a message. Timer ran out in ..... HH:MM:SS
The end time. Lets call it endTime eg:
9/15/2016 9:16:00 PM
Current time. Time current moment we live.
Lets call it currentTime.
The goal is to get a timer that is Current time - end time. Save it to a Variable TotalHours.
Then calculate the time remaining for NOW to total hours. For example TotalHours = 5. And NOW is 9/14/2016 1:16:00 PM then FinalCountDown = 6:16:00 PM. That is the timer I want running...
Here is how I am doing it...
if (info.endTime) {
var CurrentTime = new Date().toLocaleString('en-US');
moment.locale(); // en
var TotalHours = moment.utc(moment(info.diffTime, "DD/MM/YYYY HH:mm:ss").diff(moment(CurrentTime, "DD/MM/YYYY HH:mm:ss"))).format("HH:mm:ss");
info.finalCountDown= TotalHours;
};
The issue here is the following:
Case 1:
endTime = 9/15/2016 9:16:00 AM
currentTime = 9/15/2016 1:21:00 PM
TotalHours = 4:05:00
But... if its after next 2 days...
Case 2:
endTime = 9/17/2016 9:16:00 AM
currentTime = 9/15/2016 1:21:00 PM
TotalHours = 4:05:00
Total hours is still the same...
I need it to add 24hours + 24 hours + extra time = 48 + 4:05:00 = 52:05:00
also I want it to display as: 52h:05m:00s
Please let me know how to solve this...
A quick and dirty solution would be to simply convert the difference between the two date/time objects to milliseconds and then do some math on the milliseconds and format the output as follows:
var currentTime = new Date("9-15-2016 13:21:00");
var endTime = new Date("9-17-2016 09:16:00");
var ms = (endTime - currentTime); // ms of difference
var days = Math.round(ms/ 86400000);
var hrs = Math.round((ms% 86400000) / 3600000);
var mins = Math.round(((ms% 86400000) % 3600000) / 60000);
$scope.finalCountdown = (days + "d:" + hrs + " h:" + mins + "m left");
You could add in a calculation for the seconds if you needed and you can do some formatting of the numbers to have leading zeros.
However, doing this doesn't account for issues such as leap-years and other data and time anomalies. A better suggestion would be to use angular-moment which utilizes Moment.js as it can handle differences and formatting with ease.

Angularjs Django compare dates

I am fetching the date from my Django backend which comes like this: 2016-03-31
In my angular controller I want to compare it with today's date and if they are similar I want to deactivate a button.
I tried new Date() which gives me something like Thu Mar 31 2016 08:59:01 GMT+0200 (W. Europe Daylight Time)
How can these two dates be compared to achieve my goal?
ehhhhh... i think currently we could only do a manual formatting
see this one: How to format a JavaScript date
For your reference, below is what i did though:
$scope.formatDate = function(date){
var newDate = new Date(date);
var year = newDate.getFullYear();
var month = (newDate.getMonth() + 1).toString(); //add 1 as Jan is '0'
var day = newDate.getDate().toString();
month = month.length > 1? month: '0'+month;
day = day.length > 1? day: '0'+day;
$scope.date = day + '/' + month + '/' + year;
}
If you want to compare the date with now you can do the following:
var now = new Date().getTime();
var compareDate = new Date('2016-03-31').getTime();
if(now > compareDate){
//greater
}else if(now < compareDate){
//less
}else{
//equal
}
Just add what you need to the scope and then you could do something like:
ng-disabled="compareDate === today"

Why is my Cordova Geolocation so inaccurate

I'm working on a Track & Share Module for Pilots, the app is build with AngularJS within Ionic and Cordova framework. I'm currently developting and testing for android only.
The case:
There are four buttons, first checks if gps is enabled, second starts the tracking, third stops the tracking, fourth send the trackdata to the web-API if internet connection is stable. I can't guarantee 100% connectivity up in the air, so I can't send the trackdata on every tracked waypoint direct to the api - I have to store it until the aircraft is on the ground again.
The problem:
The tracked waypoints are (1) temporally/timely highly variable (I can't get any pattern on my test-tracks) and (2) the tracked altitude/heading/speed data isn't recorded on some trackpoints.
My flown test-route is about 40 minutes. I'm tracking every 60 seconds. So I must get at least minimum 35-40 trackpoints. But: I just get between 9 and 15 trackpoints on that route..
Trackpoints:
1442050712218|51.4514495|6.8892898|null|null|null; 12.9.2015 11:38:32
1442051327924|51.5183441|6.8183962|null|null|null; 12.9.2015 11:48:48
1442051511529|51.8569473|6.8611548|null|null|null; 12.9.2015 11:51:52
1442051732401|51.9828794|6.9063169|null|null|null; 12.9.2015 11:55:32
1442051912503|52.0233909|6.9596959|1300|64|52.25; 12.9.2015 11:58:33
1442052014828|52.0400627|7.0322238|1332|75|51.25; 12.9.2015 12:00:15
1442052517583|52.1472176|7.3813409|1307|70|51.5; 12.9.2015 12:08:38
1442052746410|52.1859082|7.5392811|1217|68|53; 12.9.2015 12:12:26
1442053119338|52.224271|7.874347|null|null|null; 12.9.2015 12:18:39
1442053401324|52.2677044|7.9679879|null|null|null; 12.9.2015 12:23:21
.service('TrackingFunctions', ['$interval', '$rootScope', '$localstorage', function($interval, $rootScope, $localstorage) {
// Erstellt einmalige "global" Referenz, dass immer die selbe Instanz angesprochen wird
var tracker;
this.doTracking = function(execTracking){
if(!execTracking){ // if no tracker start new
$localstorage.TRACKDATA = [];
return $interval(function(){
$localstorage.isTrackerActive = true;
var geo_options = {
enableHighAccuracy: true,
maximumAge: 30000,
timeout: 20000
};
function geo_success(position) {
console.log(position);
var tsmp = position.timestamp;
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var alt = position.coords.altitude;
var hdg = position.coords.heading;
var spd = position.coords.speed;
var ARRAYDATA = tsmp + "|" + lat + "|" + lng + "|" + alt + "|" +hdg + "|" + spd + ";";
$localstorage.TRACKDATA.push(ARRAYDATA);
}
function geo_error() {
//$scope.alt = "Fehler " + error.message + ' Error Code: ' + error.code;
}
var wpid = navigator.geolocation.getCurrentPosition(geo_success, geo_error, geo_options);
},60000); // getrackt wird alle 60 Sekunden
} else { // if tracker cancel
$interval.cancel(execTracking);
console.log("tracker deaktiviert!");
}
};
}])
How can I fix that the app tracks every 60 seconds and the missing data will be recorded, too? The function is crucial fot the app and webservice for flight-training for solo-flights of the student pilot.
Thank you.
Just an idea:
The timeout is not a accurate task, that means, timeout is working when all other tasks are done. It's more like: You should run every 60 seconds.
In your case, I would save the position continuous and would write a «clock/timer», called every second. In your script you calculate the exact starttime, e.g.: 09:27:16. After starttime + x * 60 seconds you trigger in your clock the final saving of the position.
If this is not working, I would test it by using a Web Worker.

How to Get time 2 Hours from current time in IONIC

I need to book a vehicle.So i get date.BUt i didnt got the time.Actually i want to book at least 2 hours after current time.also i need to get full time from next day onwards please help me.Iam doing in Ionic framework and AngularJS
Thanks in Advance
var timeNow = new Date().getTime();
var twoHoursIntoFuture = new Date(time + 1000 * 60 * 60 * 2);
the new Date() creates a new date object from current time. getTime() gets the time in milliseconds since January 1st, 1970. Then we just add 2 hours into timeNow (1000 * 60 * 60 * 2 milliseconds) and make a new date object based on that.
Check http://www.w3schools.com/jsref/jsref_obj_date.asp for more date manipulation info.
this.myActualDate = new Date(new Date().getTime() + (3 * 24 * 60 * 60 * 1000)).toISOString().toString().substring(0, 10);
this.myMaxDate = new Date(new Date().getTime() + (368 * 24 * 60 * 60 * 1000)).toISOString();
<ion-datetime displayFormat="YYYY/MM/DD" pickerFormat="YYYY MMMM DDDD" min={{myActualDate}} max={{myMaxDate}} [(ngModel)]="myActualDate"
formControlName="booking_date" class="flex-date" required></ion-datetime>
You can modify this code to perform yours.
If you want to extend three days in actual date then you can edit 365 digit into 368.
It will add three days in your date.
I think it will also work for time.
If you edit hours , minutes and seconds.

How to display Total Time Duration and Current Time of video

I want to display time duration of a video in silverlight 3.0 application. The format should be like 00:20 / 05:00 . ( Current Video time / Total Video Time). How to get it??.
TimeSpan _duration = mediaElement.NaturalDuration.TimeSpan;
var totalTime = string.Format("{0:00}:{1:00}", (_duration.Hours * 60) + _duration.Minutes, _duration.Seconds);
TimeSpan remaining = _duration.Subtract(mediaElement.Position);
var currentTime = string.Format("{0:00}:{1:00}", (remaining.Hours * 60) + remaining.Minutes, remaining.Seconds);
string result = string.formar("{0}/{1}",totalTime,currentTime);
Try this, Hope this can help.
Regards.

Resources