age calculation in breezingform - joomla3.0

I use Breezingforms(joomla extensions)
I have two field.
1- birthdate(persian calendar-jalali)
2-calculated_age -> textfield readonly for show Differs date.
this my code:
function showage(){
var one_year=1000*60*60*24*365;
var date1 = new Date();
var dob= ff_getElementByName('birthdate').value;
var tmp=ff_getElementByName('birthdate').value.split("/");
var date2=new Date(tmp[2],tmp[1]-1,tmp[0]);
var pattern = /[0-3][0-9]\/(0|1)[0-9]\/(19|20)[0-9]{2}/; //Regex to validate date format (dd/mm/yyyy)
if (pattern.test(dob)) {
var y1 = date1.getTime(); //getting current year
var y2 = date2.getTime(); //getting dob year
var diff=Math.floor((y1-y2)/one_year);
ff_getElementByName('calculated_age').value=diff;
}
}
I have a problem.I use var date1 = new Date(); for get current date.but this var output not Jalali date(persian date)
how solve it?

Related

Aggregate GPM hourly data to daily in GEE

I need to aggregate the sum of 48 half-hourly images per day of a GPM collection getting an imageCollection with the band "precipitationCal" and daily images
I've tried to fill and iterate an empty featureCollection but I get an empty collection without images
var dataset = ee.ImageCollection('NASA/GPM_L3/IMERG_V05')
var startdate = ee.Date.fromYMD(2014,3,1)
var enddate = ee.Date.fromYMD(2014,4,1)
var precipitation = dataset.filter(ee.Filter.date(startdate,enddate)).select('precipitationCal')
print(precipitation)
var difdate = enddate.difference(startdate, 'day')
// Time lapse
var lapse = ee.List.sequence(0, difdate.subtract(1))
var startdate = ee.Date('2014-01-01')
var listdates = lapse.map(function(day){
return startdate.advance(day, 'day')
})
var pts = ee.FeatureCollection(ee.List([]))
var newft = ee.FeatureCollection(listdates.iterate(function(img, ft) {
// Cast
ft = ee.FeatureCollection(ft)
var day = ee.Date(img)
// Filter the collection in one day
var day_collection = precipitation.filterDate(day, day.advance(1, 'day'))
// Get the sum of all 24 images into one Image
var sum = ee.Image(day_collection.sum())
// Return the FeatureCollection with the new properties set
return sum
}, listdates))
Please have a try about my package pkg_trend. aggregate_prob function in it, works just like aggregate in R language.
var imgcol_all = ee.ImageCollection('NASA/GPM_L3/IMERG_V06');
function add_date(img){
var date = ee.Date(img.get('system:time_start'));
var date_daily = date.format('YYYY-MM-dd');
return img.set('date_daily', date_daily);
}
var startdate = ee.Date.fromYMD(2014,3,1);
var enddate = ee.Date.fromYMD(2014,4,1);
var imgcol = imgcol_all
.filter(ee.Filter.date(startdate,enddate)).select('precipitationCal')
.map(add_date);
// imgcol = pkg_trend.imgcol_addSeasonProb(imgcol);
print(imgcol.limit(3), imgcol.size());
var pkgs = require('users/kongdd/pkgs:pkgs.js');
var imgcol_daily = pkgs.aggregate_prop(imgcol, "date_daily", 'sum');
print(imgcol_daily);
Map.addLayer(imgcol_daily, {}, 'precp daily');
The GEE link is https://code.earthengine.google.com/3d8c7e68e0a7a16554ff8081880bfdad
According to GEE GPM page, This product is a half-hour precipitation rate. So, to get daily sum with the code above you should divide every image in collection by 2.

React native date convert from int to date

I am new in react-native. I want to convert an int date to a formatted date.
The problem is it's always displaying the current date and not that date from the following integer: 1528101680
This is what I've tried so far:
var newDate = moment(Date(1528101680)).format('MM/DD/YYYY hh:MM');
console.log(newDate);
You need to provide time in milliseconds
var newDate = moment(new Date(1528101680 * 1000)).format('MM/DD/YYYY hh:MM');
// -----------^^^^^^^------------
console.log(newDate);
var newDate = moment(new Date(1528101680 * 1000)).format('MM/DD/YYYY hh:MM');
console.log(newDate);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.js"></script>
try this :
var newDate = moment(1528101680 * 1000).format("MM/DD/YYYY hh:MM")
console.log(newDate)
var newDate = moment(1528101680 * 1000).format("MM/DD/YYYY hh:MM")
console.log(newDate)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.js"></script>

How to convert readable date time in timestamp which comes from backend

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

convert birthday date to age in meanjs

I want to display age of all users in my meanjs app.
How can i display age instead of displaying birthdate. my plunk demo
Controller:
$scope.agedate = new Date();
$scope.calculateAge = function calculateAge(birthday) {
var ageDifMs = Date.now() - birthday.getTime();
var ageDate = new Date(ageDifMs); // miliseconds from epoch
return Math.abs(ageDate.getUTCFullYear() - 1970);
}
Html:
<p ng-bind="items.user.displayName"></p>
<p ng-bind="items.user.dateofbirth | date"></p>
<p ng-bind="calculateAge(items.user.dateofbirth)"></p>
my data:-
$scope.items = {
"_id": "5733163d4fc4b31d0ff2cb07",
"user": {
"_id": "5732f3954fc4b31d0ff2cb05",
"displayName": "karthi keyan",
"dateofbirth": "1991-10-04T18:30:00.000Z",
"profileImageURL": "./modules/users/client/img/profile/uploads/ed948b7bcd1dea2d7086a92d27367170"
},
"__v": 0,
"comments": [],
"content": "this is testing purpose for e21designs",
"categoryone": "Moral Ethics",
"category": "Anonymous Question",
"title": "Worried",
"created": "2016-05-11T11:23:41.500Z",
"isCurrentUserOwner": true
};
My plunk demo
Your code almost does what you want.
It has a problem in dateofbirth property, because it's a string (according your example.
To display it as the date you're using date filter which handles this for you.
But, in your calculateAge function you need to convert your string into Date.
Try the following:
$scope.calculateAge = function calculateAge(birthday) { // birthday is a string
var ageDifMs = Date.now() - new Date(birthday).getTime(); // parse string to date
var ageDate = new Date(ageDifMs); // miliseconds from epoch
return Math.abs(ageDate.getUTCFullYear() - 1970);
}
Hope it will help.
Please note that this problem is completely unrelated to angularjs. It is pure Javascript date differences calculation.
I strongly suggest to use a third party library like (momentjs)[http://momentjs.com/] to make such calculation, and in order to help you parse the string formatted date.
Here is a simple function in javascript to calculate age for the date format "YYYY-MM-DD". Where the dateString parameter to the function is the birth date.
function calculateAge(dateString) {
var today = new Date();
var birthDate = new Date(dateString);
var age = today.getFullYear() - birthDate.getFullYear();
var m = today.getMonth() - birthDate.getMonth();
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
return age;
}
You could use this as an angular function by applying $scope to it. Like this:
$scope.calculateAge = function(dateString) {
var today = new Date();
var birthDate = new Date(dateString);
var age = today.getFullYear() - birthDate.getFullYear();
var m = today.getMonth() - birthDate.getMonth();
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
return age;
}

Unable to change date format in Angular

I am new for Angular. I want to change date format that is sent from datepicker input.
Here is my code,
$scope.savePlaylist = function(s){
//s= 02-November-2015
var startDate = $filter('date')(s,'yyyy-MM-dd 23:59:59'); //it return 02-November-2015
var test = $filter('date')(new Date(),'yyyy-MM-dd 23:59:59');//it works!
};
So, I tried angular-moment,
$scope.savePlaylist = function(s){
//s= 02-November-2015
var startDate = $filter('amDateFormat')(s,'YYYY-MM-DD 23:59:59'); //it return empty
var test = $filter('amDateFormat')(new Date(),'YYYY-MM-DD 23:59:59');//it works!
};
I really need help. Thanks.
Try to assign date("s") to new date object and pass it to $filter. That will solve your problem.
$scope.savePlaylist = function(s){
//s= 02-November-2015
var dt = new Date(s);
var startDate = $filter('date')(dt,'yyyy-MM-dd 23:59:59'); //it return 02-November-2015
var test = $filter('date')(new Date(),'yyyy-MM-dd 23:59:59');//it works!
};
It cannot use 02-November-2015 to convert to other format. I changed it into
dd MMMM yyyy
It can work now. Thanks.

Resources