# Today is or will shortly become Saturday, April 01, 2023, day 402 of this mad

include("WBInclusions")
global outputFile = "kx.txt"

version = "012"

if isfile(outputFile)
    s = RRead(outputFile, "asis")
    if findfirst(r"[ \r\n]+[*]{3}", s) != nothing
        println(HI_RED * "\n******** Output file: " * outputFile * " exists!" * HI_END)
        exit(16)
    end
end

dt = DateTime(now()) + Hour(length(ARGS) == 0 ? 24 : (tryparse(Int64, ARGS[1]) * 24))
z0 = DateTime(dt) - DateTime("2022-02-23T00:00")
z = replace(string(div(z0, 86400000)), " milliseconds" => "")

DayOfWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
        "Saturday", "Sunday"][Dates.dayofweek(dt)]

Month = ["January", "February", "March", "April", "May", "June", "July",
        "August", "September", "October", "November", 
        "December"][tryparse(Int32,replace(string(Dates.Month(dt)), r" months?" => ""))]

Day = replace(string(Dates.Day(dt)), r" days?" => "")

if length(Day) == 1
    Day = "0" * Day
end

DATE = DayOfWeek * ", " * Month * " " * Day * ", " * string(Dates.Year(dt))[1:4] * ", day " * z

println("\n  ZZ v" * version * " (\"" * outputFile * "\")   \"" * HI_YELLOW * DATE * HI_END * "\"")

global txt = RRead("w/txts/k1.txt", "asis")

global txt = replace(txt, "***" => "")

if length(ARGS) > 0
    global txt = replace(txt,  "or will shortly become " => "")
end

global txt = replace(txt, "Saturday, April 01, 2023, day 402" => DATE)

a = open(outputFile, "w")
write(a, txt)
close(a)

run(`"\windows\System32\notepad.exe" $outputFile`)
   