MERN 1 Funzioni utili per javascript
Data formattata (Da aggiustare)
//const { Data_formattata } = require('../Funzioni_comuni')
function Data_formattata(newDate, minuti) {
// console.log('aaaaaaaaaaaaaaaaaaaaaaa')
// console.log(newDate)
let dateVariable = new Date(newDate);
if (dateVariable == 'Invalid Date') {
console.log('NON DATA ')
return ''
}
const months = {
0: 'January',
1: 'February',
2: 'March',
3: 'April',
4: 'May',
5: 'June',
6: 'July',
7: 'August',
8: 'September',
9: 'October',
10: 'November',
11: 'December',
}
const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
const d = newDate
// console.log('YYYYYYYYYYYYYYYYYYYYYYYYYYYYY NON DATA ')
const year = dateVariable.getFullYear()
const date = dateVariable.getDate()
const monthIndex = dateVariable.getMonth()
const monthName = months[dateVariable.getMonth()]
const dayName = days[dateVariable.getDay()] // Thu
const hour = dateVariable.getHours()
const minute = dateVariable.getMinutes()
let formatted = ` ${hour}:${minute} `
if (minuti > 24*60) {
let giorni = minuti / (24*60)
giorni = Math.floor(giorni)
formatted = ` ${hour}:${minute} (${giorni} giorno/i dopo) `
}
return formatted.toString()
}
// console.log('aaaaaaaaaaaaaaaaaaaaaaa')
// console.log(newDate)
let dateVariable = new Date(newDate);
if (dateVariable == 'Invalid Date') {
console.log('NON DATA ')
return ''
}
const months = {
0: 'January',
1: 'February',
2: 'March',
3: 'April',
4: 'May',
5: 'June',
6: 'July',
7: 'August',
8: 'September',
9: 'October',
10: 'November',
11: 'December',
}
const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
const d = newDate
// console.log('YYYYYYYYYYYYYYYYYYYYYYYYYYYYY NON DATA ')
const year = dateVariable.getFullYear()
const date = dateVariable.getDate()
const monthIndex = dateVariable.getMonth()
const monthName = months[dateVariable.getMonth()]
const dayName = days[dateVariable.getDay()] // Thu
const hour = dateVariable.getHours()
const minute = dateVariable.getMinutes()
let formatted = ` ${hour}:${minute} `
if (minuti > 24*60) {
let giorni = minuti / (24*60)
giorni = Math.floor(giorni)
formatted = ` ${hour}:${minute} (${giorni} giorno/i dopo) `
}
return formatted.toString()
}
Controllo che esiste la variabile nell-oggetto
function check_variabili_oggetto(obj, ...args) {
return args.reduce((obj, level) => obj && obj[level], obj)
}
return args.reduce((obj, level) => obj && obj[level], obj)
}
btn = check_variabili_oggetto (props.alunno, 'classe_id', 'nome')
if (btn === null) btn='...'
return btn
if (btn === null) btn='...'
return btn
Rimuove una riga in un array in base a _id
function removeObjectWithId(arr, _id) {
const objWithIdIndex = arr.findIndex((obj) => obj._id === _id);
if (objWithIdIndex > -1) {
arr.splice(objWithIdIndex, 1);
}
return arr;
}
const objWithIdIndex = arr.findIndex((obj) => obj._id === _id);
if (objWithIdIndex > -1) {
arr.splice(objWithIdIndex, 1);
}
return arr;
}
Array con map e ricerca all-interno di una corrispondenza
props.lista_classi_per_programma.map(function(item, index, array){
i = array_salvato_classi.findIndex(e => e._id === item._id);
if (i === -1) {
aggiungi_un_giorno_ad_array(props.item._id, item._id)
}
console.log(this) // 80
}, 80);
i = array_salvato_classi.findIndex(e => e._id === item._id);
if (i === -1) {
aggiungi_un_giorno_ad_array(props.item._id, item._id)
}
console.log(this) // 80
}, 80);
[1, , 3].map((x, index) => {
console.log(`Visit ${index}`);
return x * 2;
}),
console.log(`Visit ${index}`);
return x * 2;
}),