Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit caa21791 authored by Kevin Yung's avatar Kevin Yung
Browse files

Intégration de momentjs pour changer les dates pour plus de lisibilité

parent bcc77d22
{"jwt":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJjaGlycHN0YWNrLWFwcGxpY2F0aW9uLXNlcnZlciIsImV4cCI6MTYxNTkxMDIxMiwiaXNzIjoiY2hpcnBzdGFjay1hcHBsaWNhdGlvbi1zZXJ2ZXIiLCJuYmYiOjE2MTU4MjM4MTIsInN1YiI6InVzZXIiLCJ1c2VybmFtZSI6IkNoaXJwc3RhY2tNb25pdG9yaW5nIn0.WMcgbg-Mi4QecWM-MkZ4WImwycGyHuH2Rvqj1tXsGPo"}
\ No newline at end of file
{"jwt":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJjaGlycHN0YWNrLWFwcGxpY2F0aW9uLXNlcnZlciIsImV4cCI6MTYxNTk5NTIxMiwiaXNzIjoiY2hpcnBzdGFjay1hcHBsaWNhdGlvbi1zZXJ2ZXIiLCJuYmYiOjE2MTU5MDg4MTIsInN1YiI6InVzZXIiLCJ1c2VybmFtZSI6IkNoaXJwc3RhY2tNb25pdG9yaW5nIn0.xFYJP6kBVTKT83xe_T2U25p96N3OQvFA1HWVqEmNUqA"}
\ No newline at end of file
const moment = require('moment');
var argv = process.argv; // store the argument given
process.argv.shift(); // skip path of node file
process.argv.shift(); // skip path of js file
argv = process.argv.join(" ") // parse to keep only the string
function f(lastSeenAt) {
//console.log(lastSeenAt);
lastSeenAt = new Date(lastSeenAt);
return moment(lastSeenAt).fromNow();
}
console.log(f(argv))
\ No newline at end of file
......@@ -91,6 +91,13 @@ do
fi
fi
done
if [[ ${date[$i]} != "null" ]]
then
tmp=$(grep ${id[$i]} < .gateways.html)
dateFromNow=$(node changeDateMomentjs.js ${date[$i]})
replacement=${tmp/${date[$i]}/"$dateFromNow"}
sed -i "/${id[$i]}/c $replacement" .gateways.html
fi
done
#On met à jour les states des gateways pour le prochain jour
......@@ -111,63 +118,4 @@ echo " {
\"lastState\": \"${state[$((${#id[@]}-1))]}\"
}
]
}" >> lastGatewaysStates.json
#jq --raw-output -f gateways_to_html.jq .gateways.json | grep "0000024b0805031a"
#jq --raw-output ".result" .gateways.json
#jq -c ".result | sort_by(.lastSeenAt, .id) | reverse []" .gateways.json
#data=()
#objects=()
#id=()
#lastSeenAt=()
#i=0
#while read x
#do
# data[$i]=$(echo $x | tr "," "\n")
# i=$((i+1))
#done <data.txt
#
#echo ${data[1]}
#echo "---"
#j=0
#cpt=$((${#data[@]}-1))
#for (( j=0; j<=$cpt; j++ ))
#do
# echo ${data[$j]}
# echo "---"
#
# #On récupère toutes les id dans le tableau id
# tmp=$(echo ${data[$j]} | tr [:space:] "_" | sed -e 's,"id":,\n,g')
# k=0
# for d in $tmp
# do
# objects[$k]=$d
# k=$((k+1))
# done
# tmp=$(echo ${objects[1]} | tr "_" "\n")
# for a in $tmp
# do
# id[$j]=$a
# break
# done
#
# #On récupère toutes les dates lastSeenAt dans un tableau (qui représentera le champ pour chaque id)
# #tmp
#done
#
#echo ${id[0]}
#echo ${id[1]}
#echo ${id[2]}
#echo ${id[3]}
##echo $test
##echo ${objects[1]}
\ No newline at end of file
}" >> lastGatewaysStates.json
\ No newline at end of file
#!/usr/bin/env node
const moment = require('moment');
var argv = process.argv; // store the argument given
process.argv.shift(); // skip path of node file
process.argv.shift(); // skip path of js file
argv = process.argv.join(" ") // parse to keep only the string
function f(lastSeenAt) {
//console.log(lastSeenAt);
lastSeenAt = new Date(lastSeenAt);
return moment(lastSeenAt).fromNow();
}
console.log(f(argv))
\ No newline at end of file
#!/bin/bash
var="2021-03-16T14:20:40.327687Z"
a=$(node test.js $var)
echo "$a"
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