ajout des fonctions de gestion des dates à awk
This commit is contained in:
parent
563338cd02
commit
4b44a52033
|
@ -1 +1 @@
|
|||
007015000
|
||||
007016000
|
||||
|
|
|
@ -1800,6 +1800,10 @@ function ensure_hostname() {
|
|||
}
|
||||
|
||||
__AWKDEF_FUNCTIONS='
|
||||
function num(s) {
|
||||
if (s ~ /^[0-9]+$/) return int(s)
|
||||
else return s
|
||||
}
|
||||
function quote_html(s) {
|
||||
gsub(/&/, "\\&", s)
|
||||
gsub(/"/, "\\"", s)
|
||||
|
@ -1850,6 +1854,52 @@ function unquote_mysqlcsv(s) {
|
|||
gsub(/\\\\/, "\\", s)
|
||||
return s
|
||||
}
|
||||
|
||||
function __parse_date_fr(date, parts, y, m, d) {
|
||||
if (match(date, /([0-9][0-9]?)\/([0-9][0-9]?)\/([0-9][0-9][0-9][0-9])/, parts)) {
|
||||
y = int(parts[3])
|
||||
m = int(parts[2])
|
||||
d = int(parts[1])
|
||||
return mktime(sprintf("%04i %02i %02i 00 00 00 +0400", y, m, d))
|
||||
}
|
||||
return -1
|
||||
}
|
||||
function __parse_date_mysql(date, parts, y, m, d) {
|
||||
if (match(date, /([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])/, parts)) {
|
||||
y = int(parts[1])
|
||||
m = int(parts[2])
|
||||
d = int(parts[3])
|
||||
return mktime(sprintf("%04i %02i %02i 00 00 00 +0400", y, m, d))
|
||||
}
|
||||
return -1
|
||||
}
|
||||
function __parse_date_any(date, serial) {
|
||||
serial = __parse_date_fr(date)
|
||||
if (serial == -1) serial = __parse_date_mysql(date)
|
||||
return serial
|
||||
}
|
||||
function date_serial(date) {
|
||||
return __parse_date_any(date)
|
||||
}
|
||||
function date_parse(date, serial) {
|
||||
serial = __parse_date_any(date)
|
||||
if (serial == -1) return date
|
||||
return strftime("%d/%m/%Y", serial)
|
||||
}
|
||||
function date_monday(date, serial, dow) {
|
||||
serial = __parse_date_any(date)
|
||||
if (serial == -1) return date
|
||||
dow = strftime("%u", serial)
|
||||
serial -= (dow - 1) * 86400
|
||||
return strftime("%d/%m/%Y", serial)
|
||||
}
|
||||
function date_add(date, nbdays, serial) {
|
||||
serial = __parse_date_any(date)
|
||||
if (serial == -1) return date
|
||||
serial += nbdays * 86400
|
||||
return strftime("%d/%m/%Y", serial)
|
||||
}
|
||||
|
||||
function array_new(dest) {
|
||||
dest[0] = 0 # forcer awk à considérer dest comme un tableau
|
||||
delete dest
|
||||
|
|
Loading…
Reference in New Issue