Skip to content

Commit 98070d0

Browse files
committed
Added inline lua script for yaml for better readability suggestion from pat.
Signed-off-by: fahadahammed <[email protected]>
1 parent 7342199 commit 98070d0

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pipeline/filters/lua.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,25 @@ pipeline:
513513
filters:
514514
- name: lua
515515
match: '*'
516-
script: custom_datetime_format.lua
516+
code: |
517+
function convert_to_utc(tag, timestamp, record)
518+
local date_time = record["pub_date"]
519+
local new_record = record
520+
if date_time then
521+
if string.find(date_time, ",") then
522+
local pattern = "(%a+, %d+ %a+ %d+ %d+:%d+:%d+) ([+-]%d%d%d%d)"
523+
local date_part, zone_part = date_time:match(pattern)
524+
if date_part and zone_part then
525+
local command = string.format("date -u -d '%s %s' +%%Y-%%m-%%dT%%H:%%M:%%SZ", date_part, zone_part)
526+
local handle = io.popen(command)
527+
local result = handle:read("*a")
528+
handle:close()
529+
new_record["pub_date"] = result:match("%S+")
530+
end
531+
end
532+
end
533+
return 1, timestamp, new_record
534+
end
517535
call: convert_to_utc
518536

519537
outputs:

0 commit comments

Comments
 (0)