EuGTK Days Between Dates
- Posted by Senator Jul 20, 2018
- 2802 views
Irv Mullins has released EuGTK 4.14.0
-- -- GTK Days Between Dates, requires OpenEuphoria 4.x -- a simple EuGTK demo program by Kenneth Rhodes -- -- Check out Irv Mullins EuGTk 4.14.0 -- https://sites.google.com/site/euphoriagtk/Home/ -- include std/datetime.e include std/convert.e include GtkEngine.e datetime dt1, dt2 object sd, ed atom yyyy,mm,dd sequence wdn1, wdn2 -- week day name constant instructions = { "Calculate the number of days between dates", """ Enter numeric values for starting date, and ending date in the format yyyymmdd The program displays the number of days between the starting and ending date as well as the week day names of the starting and ending dates """} constant -- INTERFACE win = create(GtkWindow,"title = Compute Days Between Dates,size=300x50,border=10,$destroy=Quit"), pan = create(GtkBox,"orientation=VERTICAL,spacing=10"), StartDate = create(GtkEntry,"placeholder text= Start Date yyyymmdd e.g. 20180628"), EndDate = create(GtkEntry,"placeholder text= EndDate yyyymmdd e.g. 20180807"), btnbox = create(GtkButtonBox), btn1 = create(GtkButton,"gtk-quit","Quit"), btn2 = create(GtkButton,"gtk-help","Help"), btn3 = create(GtkButton,"gtk-ok","GetDaysBetweenDates") gtk:add(win,pan) gtk:add(pan,{StartDate, EndDate}) pack_end(pan,btnbox) gtk:add(btnbox,{btn1,btn2,btn3}) set(btn3,"grab focus") show_all(win) main() --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- -- You might want to add these functions to std/datetime.e -- --------------------------------------------------------------------------------------------------- global function DaysBetweenDates(datetime dt1, datetime dt2) -- return floor(diff(dt1,dt2)/86400) -- 86400 = seconds in a day -- end function -- -- global function week_day_name(datetime dt) -- return {day_names[weeks_day(dt)]} -- end function -- ----------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------- -------------------------------- global function Help() -- -------------------------------- return Info(win,"instructions",instructions[1],instructions[2]) end function ---------------------------------------------------------- global function GetDaysBetweenDates() -- ----------------------------------------------------------- atom dbd sd = get(StartDate,"text") sd = to_string(sd) ed= get(EndDate,"text") ed = to_string(ed) yyyy = to_number(sd[1..4]) mm = to_number(sd[5..6]) dd = to_number(sd[7..8]) dt1 = {yyyy,mm,dd,0,0,0} wdn1 = week_day_name(dt1) yyyy = to_number(ed[1..4]) mm = to_number(ed[5..6]) dd = to_number(ed[7..8]) dt2 = {yyyy,mm,dd, 0,0,0} wdn2 = week_day_name(dt2) dbd = DaysBetweenDates(dt1,dt2) Info(win, "Days Between Dates", text:format("There are [] days between [] [] and [] []", {dbd, wdn1, sd, wdn2, ed})) return 1 end function