mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-22 20:19:21 +00:00
Created diffToTime function
This commit is contained in:
parent
375a0ef13a
commit
6a1f441da6
@ -12,18 +12,30 @@
|
|||||||
background-color: #fff3ff80;
|
background-color: #fff3ff80;
|
||||||
top: 0px;
|
top: 0px;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 50px;
|
|
||||||
transition: width 1s;
|
|
||||||
font-size: 70%;
|
|
||||||
padding-top: 50px;
|
padding-top: 50px;
|
||||||
|
|
||||||
|
/**
|
||||||
|
width: 50px;
|
||||||
|
font-size: 70%;
|
||||||
|
transition: width 1s;
|
||||||
|
*/
|
||||||
|
|
||||||
|
width: 230px;
|
||||||
|
transition: right 1s;
|
||||||
|
right: -175px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#friendsList:hover {
|
#friendsList:hover {
|
||||||
width: 230px;
|
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
|
|
||||||
|
/**
|
||||||
|
width: 230px;
|
||||||
font-size: 100%;
|
font-size: 100%;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
padding-top: 50px;
|
padding-top: 50px;
|
||||||
|
*/
|
||||||
|
|
||||||
|
right: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#friendsList td {
|
#friendsList td {
|
||||||
|
86
assets/js/common/date.js
Normal file
86
assets/js/common/date.js
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
/**
|
||||||
|
* The date library
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
*/
|
||||||
|
|
||||||
|
ComunicWeb.common.date = {
|
||||||
|
/**
|
||||||
|
* Get current timestamp
|
||||||
|
*
|
||||||
|
* @return {Integer} The current timestamp
|
||||||
|
*/
|
||||||
|
time: function(){
|
||||||
|
return Math.floor(new Date().getTime()/1000);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a difference in second into a date
|
||||||
|
*
|
||||||
|
* @param {Integer} difference The difference between two values
|
||||||
|
* @return {String} The generated date
|
||||||
|
*/
|
||||||
|
diffToStr: function(difference){
|
||||||
|
//Calculate seconds
|
||||||
|
var seconds = difference-Math.floor(difference/60)*60;
|
||||||
|
var difference = (difference - seconds)/60;
|
||||||
|
|
||||||
|
//Check there was less than one minute
|
||||||
|
if(difference == 0)
|
||||||
|
return seconds + "s";
|
||||||
|
|
||||||
|
|
||||||
|
//Calculate minutes
|
||||||
|
var minutes = difference-Math.floor(difference/60)*60;
|
||||||
|
var difference = (difference - minutes)/60;
|
||||||
|
|
||||||
|
//Check there was less than one hour
|
||||||
|
if(difference == 0)
|
||||||
|
return minutes + "min";
|
||||||
|
|
||||||
|
|
||||||
|
//Calculate hours
|
||||||
|
var hours = difference-Math.floor(difference/24)*24;
|
||||||
|
var difference = (difference - hours)/24;
|
||||||
|
|
||||||
|
//Check there was less than a day
|
||||||
|
if(difference == 0)
|
||||||
|
return hours + "h";
|
||||||
|
|
||||||
|
|
||||||
|
//Calculate days
|
||||||
|
var days = difference-Math.floor(difference/30)*30;
|
||||||
|
var difference = (difference - days)/30;
|
||||||
|
|
||||||
|
//Check there was less than a month
|
||||||
|
if(difference == 0){
|
||||||
|
if(days == 1)
|
||||||
|
return "1 day";
|
||||||
|
else
|
||||||
|
return days + " days";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Calculate months
|
||||||
|
var months = difference-Math.floor(difference/12)*12;
|
||||||
|
var difference = (difference - months)/12;
|
||||||
|
|
||||||
|
//Check there was less than a year
|
||||||
|
if(difference == 0){
|
||||||
|
if(months == 1)
|
||||||
|
return "1 month";
|
||||||
|
else
|
||||||
|
return months + " months";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Calculate years
|
||||||
|
var years = difference;
|
||||||
|
if(years == 1){
|
||||||
|
return "1 year";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return years + " years";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
@ -219,6 +219,13 @@ var ComunicWeb = {
|
|||||||
*/
|
*/
|
||||||
executeJSsource: function(source){},
|
executeJSsource: function(source){},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The date library
|
||||||
|
*/
|
||||||
|
date:{
|
||||||
|
//TODO: implement
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -114,7 +114,23 @@ ComunicWeb.components.friends.bar = {
|
|||||||
var nameRow = createElem("td", friendRow);
|
var nameRow = createElem("td", friendRow);
|
||||||
nameRow.innerHTML = usersInfos["user-"+friendID].firstName + " " + usersInfos["user-"+friendID].lastName;
|
nameRow.innerHTML = usersInfos["user-"+friendID].firstName + " " + usersInfos["user-"+friendID].lastName;
|
||||||
|
|
||||||
console.log(usersInfos["user-"+friendID]);
|
//Add user login status
|
||||||
|
var statusRow = createElem("td", friendRow);
|
||||||
|
var iconsStats = createElem("i", statusRow);
|
||||||
|
iconsStats.className = "fa fa-fw fa-circle";
|
||||||
|
|
||||||
|
//Check if user is online or not
|
||||||
|
var currentTime = ComunicWeb.common.date.time();
|
||||||
|
var timeDifference = currentTime - friendsList[i].time_last_activity;
|
||||||
|
|
||||||
|
if(timeDifference < 30){
|
||||||
|
//User is logged in
|
||||||
|
iconsStats.style.color = "green";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//User isn't logged in
|
||||||
|
statusRow.innerHTML = ComunicWeb.common.date.diffToStr();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -61,6 +61,7 @@ $config['JSfiles'] = array(
|
|||||||
"%PATH_ASSETS%js/common/page.js",
|
"%PATH_ASSETS%js/common/page.js",
|
||||||
"%PATH_ASSETS%js/common/notifications.js",
|
"%PATH_ASSETS%js/common/notifications.js",
|
||||||
"%PATH_ASSETS%js/common/formChecker.js",
|
"%PATH_ASSETS%js/common/formChecker.js",
|
||||||
|
"%PATH_ASSETS%js/common/date.js",
|
||||||
"%PATH_ASSETS%js/common/system.js",
|
"%PATH_ASSETS%js/common/system.js",
|
||||||
|
|
||||||
//Components
|
//Components
|
||||||
|
Loading…
Reference in New Issue
Block a user