Skip to content
This repository was archived by the owner on Apr 3, 2018. It is now read-only.

Commit 532bc63

Browse files
committed
Fix #43 + Rewrite convert1To2digits
1 parent 964af10 commit 532bc63

File tree

1 file changed

+60
-42
lines changed

1 file changed

+60
-42
lines changed

funceble

+60-42
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ noFiles=false
7272

7373
# Generate debug file under log
7474
# DO NOT USE THIS IF YOU DON'T KNOW HOW TO DEBUG FROM OUTPUTTED FILE
75-
debugUnknown=true
75+
debugUnknown=false
7676

7777
# Defaut name for hosts file
7878
hostsDefault='hosts'
@@ -749,7 +749,7 @@ getExpirationDate(){
749749

750750
# Here's a list of words the ${content} have to match to get the
751751
# expiration date from the whois record of domain
752-
local toMatch=('expire:' 'Expiration Date:' 'expire on:' 'Expiry Date:' 'free-date' 'expires:' 'Expiration date:' 'Expiry date:' 'Expire Date:' 'renewal date:' 'Expires:' 'validity:' 'Expiration Date :' 'Expiry :' 'expires at:' 'domain_datebilleduntil:' 'Data de expiração \/ Expiration Date \(dd\/mm\/yyyy\):' 'Fecha de expiración \(Expiration date\):' '\[Expires on\]' 'Record expires on' 'status: OK-UNTIL' 'renewal:' 'expires............:' 'expire-date:')
752+
local toMatch=('expire:' 'Expiration Date:' 'expire on:' 'Expiry Date:' 'free-date' 'expires:' 'Expiration date:' 'Expiry date:' 'Expire Date:' 'renewal date:' 'Expires:' 'validity:' 'Expiration Date :' 'Expiry :' 'expires at:' 'domain_datebilleduntil:' 'Data de expiração \/ Expiration Date \(dd\/mm\/yyyy\):' 'Fecha de expiración \(Expiration date\):' '\[Expires on\]' 'Record expires on' 'status: OK-UNTIL' 'renewal:' 'expires............:' 'expire-date:' 'Exp date:')
753753

754754
for i in ${!toMatch[*]}
755755
do
@@ -875,46 +875,30 @@ getMonthInEnglish(){
875875
# @CalledBy formatDate
876876
################################################################################
877877
convert1To2digits(){
878-
oneDigit="${1}"
878+
local number="${1}"
879+
local monthOrDay="${2}"
879880

880-
local regex='(?<!\S)\d(?!\S)'
881-
if [[ ${oneDigit} =~ regex ]]
882-
then
883-
case ${oneDigit} in
884-
1)
885-
month='01'
886-
;;
887-
2)
888-
month='02'
889-
;;
890-
3)
891-
month='03'
892-
;;
893-
4)
894-
month='04'
895-
;;
896-
5)
897-
month='05'
898-
;;
899-
6)
900-
month='06'
901-
;;
902-
7)
903-
month='07'
904-
;;
905-
8)
906-
month='08'
907-
;;
908-
9)
909-
month='09'
910-
;;
911-
*)
912-
month='00'
913-
;;
914-
esac
915-
else
916-
month=${oneDigit}
917-
fi
881+
local regex="^\d"
882+
883+
local validNumber=('1' '2' '3' '4' '5' '6' '7' '8' '9')
884+
local null='0'
885+
886+
for i in ${!validNumber[*]}
887+
do
888+
if [[ ${number} == ${validNumber[${i}]} ]]
889+
then
890+
case "${monthOrDay}" in
891+
month)
892+
month=${null}${number}
893+
break
894+
;;
895+
day)
896+
day=${null}${number}
897+
break
898+
;;
899+
esac
900+
fi
901+
done
918902
}
919903

920904
################################ Format Date ###################################
@@ -979,6 +963,8 @@ formatDate()
979963
local regex26='[0-9]{2}-[A-Z]{1}[a-z]{2}-[0-9]{4}'
980964
# Date in format: 02.1.2017 // Month: jan
981965
local regex27='[0-9]{2}\.[0-9]{1}\.[0-9]{4}'
966+
# Date in format: 02 Jan 2017
967+
local regex28='[0-9]\s[A-Z]{1}[a-z]{2}\s[0-9]{4}'
982968

983969
if [[ "${expirationDate}" =~ ${regex1} || "${expirationDate}" =~ ${regex11} || "${expirationDate}" =~ ${regex26} ]]
984970
then
@@ -1036,14 +1022,46 @@ formatDate()
10361022
local year=$(echo "${expirationDate}" | tr -cd '[[:digit:]]' | tail -c4)
10371023

10381024
# We convert the month
1039-
convert1To2digits "${month}"
1025+
convert1To2digits "${month}" "month"
10401026

10411027
# We convert the month to alpha format
10421028
getMonthInEnglish "${month}"
10431029

10441030
# We assign the expiration date
10451031
expirationDate=${day}'-'${month}'-'${year}
10461032

1033+
# We convert it to lower case
1034+
dateToLower
1035+
elif [[ "${expirationDate}" =~ ${regex28} ]]
1036+
then
1037+
# We split the date
1038+
local month=$(echo "${expirationDate}" | tr -cd '[[:alpha:]]' | head -c3)
1039+
local year=$(echo "${expirationDate}" | tr -cd '[[:digit:]]' | tail -c4)
1040+
local day=$(echo "${expirationDate}" | tr -cd '[[:digit:]]' | head -c4)
1041+
1042+
# We get the last 2 digits of the day
1043+
local dayEnd=$(echo "${day}" | tr -cd '[[:digit:]]' | tail -c2)
1044+
1045+
# We use 20 to check if it's a 1 or 2 digts day
1046+
# Case:
1047+
# 2 Jan 2017
1048+
# Result: 2201
1049+
# 02 Jan 2017-01
1050+
# Result: 0220
1051+
# So if the last 2 digts are not 20, it's a 1 digit day
1052+
if [[ ${dayEnd} == '20' ]]
1053+
then
1054+
local day=$(echo "${day}" | tr -cd '[[:digit:]]' | head -c2)
1055+
else
1056+
local day=$(echo "${day}" | tr -cd '[[:digit:]]' | head -c1)
1057+
1058+
# We convert the day
1059+
convert1To2digits "${day}" "day"
1060+
fi
1061+
1062+
# We assign the expiration date
1063+
expirationDate=${day}'-'${month}'-'${year}
1064+
10471065
# We convert it to lower case
10481066
dateToLower
10491067
else

0 commit comments

Comments
 (0)