From 586639907bbcf568089c04aced6669116888cdbf Mon Sep 17 00:00:00 2001 From: kaotisk Date: Sun, 16 Mar 2025 01:29:32 +0200 Subject: All date functions accumulated in _ak_utils --- bin/ak-mine | 3 ++- bin/ak-profile | 3 ++- bin/ak-transactions | 3 ++- lib/_ak_network_yggdrasil | 3 ++- lib/_ak_utils | 12 ++++++++++++ lib/_ak_zblock | 15 ++++++++------- lib/_ak_zchain | 5 +++-- modules/articles/main.sh | 3 ++- modules/categories/main.sh | 3 ++- modules/comments/main.sh | 3 ++- modules/files/main.sh | 3 ++- modules/folders/main.sh | 3 ++- modules/mixtapes/lib.sh | 16 ++++++++-------- modules/news/lib.sh | 3 ++- modules/reference/main.sh | 7 ++++--- modules/repositories/main.sh | 1 + modules/smfiles/lib.sh | 3 ++- modules/todos/main.sh | 3 ++- 18 files changed, 60 insertions(+), 32 deletions(-) diff --git a/bin/ak-mine b/bin/ak-mine index 46e106d..00c7458 100755 --- a/bin/ak-mine +++ b/bin/ak-mine @@ -31,6 +31,7 @@ descriptionString="Sblock mining" source $AK_LIBDIR/_ak_log source $AK_LIBDIR/_ak_script +source $AK_LIBDIR/_ak_utils gather_zblocks(){ if [ "$(cat $AK_ZBLOCKSFILE | jq -r '.[].zblock' | wc -l)" -ne 0 ] @@ -56,7 +57,7 @@ proofofwork(){ i=1 l=1; while [ $l = 1 ] do - TIMESTAMP="$(date -u +%s)" + TIMESTAMP="$(_ak_datetime_unix)" SHA="$(echo -n $TEST'"nonce":"'$i'","previous":"'$PRE'","timestamp":"'$TIMESTAMP'","miner":"'$MINER'","reward":"40"}' | sha512sum | awk '{ print $1 }')" # Static difficulty for securing the sblock echo $SHA | grep -e '^000' diff --git a/bin/ak-profile b/bin/ak-profile index 97dcce3..a6ce3c8 100755 --- a/bin/ak-profile +++ b/bin/ak-profile @@ -45,6 +45,7 @@ ZPROFILEDIR="$AK_WORKDIR/profile" source $AK_LIBDIR/_ak_log source $AK_LIBDIR/_ak_script +source $AK_LIBDIR/_ak_utils source $AK_LIBDIR/_ak_ipfs source $AK_LIBDIR/_ak_gpg source $AK_LIBDIR/_ak_zblock @@ -202,7 +203,7 @@ _ak_modules_profile_add(){ FILE_SIGNATURE=$(_ak_ipfs_add $FILE_SIGN_FILE) cat > data < data <. ### source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_utils function _ak_network_yggdrasil_scan_full(){ # This scan is using HIA resources to scan the whole cjdns network for peers @@ -65,7 +66,7 @@ function _ak_network_yggdrasil_scan_full(){ count="$(( $count + 1 ))" _ak_log_debug "Scanning [${count}/${max}] $ip..." node_fs_path="$AK_ZPEERSDIR/ygg/$(echo -n $ip| sed 's/://g')" - scan_ts="$(date -u +%s)" + scan_ts="$(_ak_datetime_unix)" if [ ! -d ${node_fs_path} ] then mkdir -p ${node_fs_path} diff --git a/lib/_ak_utils b/lib/_ak_utils index d437cb9..d9204e9 100755 --- a/lib/_ak_utils +++ b/lib/_ak_utils @@ -21,6 +21,18 @@ function _ak_datetime_unix(){ date -u +%s | tr -d '\n' } +function _ak_datetime_unix_nanosecs(){ + date -u +%s.%N | tr -d '\n' +} + +function _ak_datetime_human(){ + date -u +%Y%m%d_%H%M%S +} + +function _ak_datetime_human_date_only(){ + date -u +%Y%m%d +} + function _ak_datetime_unix_to_human(){ if [ ! -z $1 ] && [ -n "$1" ] && [ "$(echo $1 | sed -e 's/[0-9]\{10\}//g')" == "" ] then diff --git a/lib/_ak_zblock b/lib/_ak_zblock index b4a546b..1313127 100755 --- a/lib/_ak_zblock +++ b/lib/_ak_zblock @@ -20,6 +20,7 @@ #set -x source $AK_LIBDIR/_ak_log source $AK_LIBDIR/_ak_script +source $AK_LIBDIR/_ak_utils source $AK_LIBDIR/_ak_gpg source $AK_LIBDIR/_ak_html source $AK_LIBDIR/_ak_ipfs @@ -452,7 +453,7 @@ function _ak_zblock_show(){ # } function _ak_zblock_gen_html(){ - time_started=$(date -u +%s.%N) + time_started=$(_ak_datetime_unix_nanosecs) ss=$(echo $time_started | cut -d '.' -f 1) nss=$(echo $time_started | cut -d '.' -f 2) # Check if there are enough arguments @@ -475,11 +476,11 @@ function _ak_zblock_gen_html(){ _ak_zblock_show "$1" | jq > $arg _ak_generate_html_header > zblock-$1.html _ak_generate_html_zblock $arg >> zblock-$1.html - time_ended=$(date -u +%s.%N) + time_ended=$(_ak_datetime_unix_nanosecs) se=$(echo $time_ended | cut -d '.' -f 1) nse=$(echo $time_ended | cut -d '.' -f 2) printf '
\n' >> zblock-$1.html - printf '