@osimatic/helpers-js 1.1.64 → 1.1.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG CHANGED
@@ -69,3 +69,8 @@ ImportFromCsv.initModal() -> ImportFromCsv.initForm()
69
69
 
70
70
  1.1.44
71
71
  Toutes les fonctions des classes SqlTime, SqlDate et SqlDateTime prennent maintenant les dates et heures SQL en UTC. CECI EST TRES IMPORTANT SINON CELA FAUSSE LES DATES/HEURES SELON LES FUSEAUX HORAIRES.
72
+
73
+ 1.1.66
74
+ Duration.convertToDurationAsCentieme() -> Duration.convertToDurationAsHundredthOfAnHour()
75
+
76
+
package/duration.js CHANGED
@@ -1,6 +1,8 @@
1
1
 
2
2
  class Duration {
3
3
 
4
+ // ---------- Nb jours ----------
5
+
4
6
  static formatNbDays(nbDays, locale='fr-FR') {
5
7
  return new Intl.NumberFormat(locale, {
6
8
  minimumFractionDigits: 2,
@@ -14,15 +16,7 @@ class Duration {
14
16
  return '<span class="text-'+(nbDays<0?'danger':'success')+'">'+this.formatNbDays(nbDays)+'</span>';
15
17
  }
16
18
 
17
- static convertToDurationAsCentieme(durationInSeconds) {
18
- let hour = Math.floor(durationInSeconds / 3600);
19
- let minutes = durationInSeconds % 3600;
20
- minutes = Math.floor(minutes / 60);
21
- // minutes = minutes - (minutes % 60);
22
- let minCentieme = Math.round( (minutes / 60 ) * 100 );
23
- return hour+(minCentieme/100);
24
- //return parseFloat(hour+'.'+minCentieme);
25
- }
19
+ // ---------- Durée en seconde ----------
26
20
 
27
21
  static convertToDurationAsInputTimeValue(durationInSeconds) {
28
22
  return Duration.convertToDurationInHourChronoDisplay(Math.abs(durationInSeconds), 'input_time');
@@ -164,6 +158,27 @@ class Duration {
164
158
  return durationInSeconds % 60;
165
159
  }
166
160
 
161
+ // ---------- Durée en centième d'heure ----------
162
+
163
+ static convertToDurationAsHundredthOfAnHour(durationInSeconds) {
164
+ let hour = Math.floor(durationInSeconds / 3600);
165
+ let minutes = durationInSeconds % 3600;
166
+ minutes = Math.floor(minutes / 60);
167
+ // minutes = minutes - (minutes % 60);
168
+ let minCentieme = Math.round( (minutes / 60 ) * 100 );
169
+ return hour+(minCentieme/100);
170
+ //return parseFloat(hour+'.'+minCentieme);
171
+ }
172
+
173
+ static getNbHoursOfHundredthOfAnHour(durationAsHundredthOfAnHour) {
174
+ return Math.trunc(durationAsHundredthOfAnHour);
175
+ }
176
+
177
+ static getNbMinutesOfHundredthOfAnHour(durationAsHundredthOfAnHour) {
178
+ return Math.floor(Math.getDecimals(Math.roundDecimal(durationAsHundredthOfAnHour, 2)) / 100 * 60);
179
+ }
180
+
181
+
167
182
  }
168
183
 
169
184
  module.exports = { Duration };
package/network.js CHANGED
@@ -40,6 +40,12 @@ class UrlAndQueryString {
40
40
  return (withLink ? '<a href="' + url + '">' : '') + formattedUrl + (withLink ? '</a>' : '');
41
41
  }
42
42
 
43
+ static urlify(text) {
44
+ return text.replace(/(https?:\/\/[^\s]+)/g, url => '<a href="' + url + '">' + url + '</a>');
45
+ // or alternatively
46
+ // return text.replace(urlRegex, '<a href="$1">$1</a>')
47
+ }
48
+
43
49
  static getHost(url, withProtocol=true) {
44
50
  if (typeof url == 'undefined') {
45
51
  return withProtocol ? window.location.origin : window.location.host;
package/number.js CHANGED
@@ -87,6 +87,10 @@ Number.roundDecimal = Number.roundDecimal || function(number, precision) {
87
87
  return Math.round(number*tmp) / tmp;
88
88
  }
89
89
 
90
+ Math.getDecimals = Math.getDecimals || function(number) {
91
+ return parseInt((number+"").split(".")[1]);
92
+ }
93
+
90
94
  if (!Number.random) {
91
95
  Number.random = function(min, max) {
92
96
  return Math.floor(Math.random() * (max - min + 1)) + min;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.1.64",
3
+ "version": "1.1.66",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"