Commit ee0d5707 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Move the JavaScript function reprDuration as a global function in app.js.

parent 72ae3edc
...@@ -28,6 +28,50 @@ Ext.require('TrackEvents.form.field.UserData'); ...@@ -28,6 +28,50 @@ Ext.require('TrackEvents.form.field.UserData');
Ext.require('TrackEvents.form.field.UserDataMultiDefault'); Ext.require('TrackEvents.form.field.UserDataMultiDefault');
Ext.require('TrackEvents.form.plugin.UserDataConsistency'); Ext.require('TrackEvents.form.plugin.UserDataConsistency');
/**
* Global function vonverting a duration in nanosecond into a string.
*
* @param {Number} value
* The duration in seconds
*
* @return {String}
* The duration express as the number of year + the number of months
* e.g. "3y + 09m"
*
*/
reprDuration = function (value) {
"use strict";
var duration = value,
month, nd, nm, ny, rep, year;
// duration of year and month in seconds
year = 365 * 24 * 3600;
month = year / 12;
// number of years and months
ny = Math.floor(duration / year);
nm = Math.floor((duration - ny * year) / month);
// format the number of month
nm = Ext.String.leftPad(nm.toString(), 2, '0');
// format the response
if (ny > 0) {
rep = Ext.String.format("{0}y + {1}m", ny, nm);
} else if (nm > 0) {
rep = Ext.String.format("{0}m", nm);
} else {
nd = duration / (24 * 3600);
rep = Ext.String.leftPad(nd.toString(), 2, '0');
}
return rep;
};
Ext.onReady(function(){ Ext.onReady(function(){
"use strict"; "use strict";
......
/**
* Convert a duration in nanosecond into a string.
*
* @param {Number} value
* The duration in seconds
*
* @return {String}
* The duration express as the number of year + the number of months e.g. "3y + 09m"
*
*/
function reprDuration(value) {
"use strict";
var duration = value,
month,
nd,
nm,
ny,
rep,
year;
// duration of year and month in seconds
year = 365 * 24 * 3600;
month = year / 12;
// number of years and months
ny = Math.floor(duration / year);
nm = Math.floor((duration - ny * year) / month);
// format the number of month
nm = Ext.String.leftPad(nm.toString(), 2, '0');
// format the response
if (ny > 0) {
rep = Ext.String.format("{0}y + {1}m", ny, nm);
} else if (nm > 0) {
rep = Ext.String.format("{0}m", nm);
} else {
nd = duration / (24 * 3600);
rep = Ext.String.leftPad(nd.toString(), 2, '0');
}
return rep;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment