Re: EuGTK Days Between Dates

new topic     » goto parent     » topic index » view thread      » older message » newer message

I've updated the parsing function to be more versatile when typing in dates.

Date formats include: m/d/yyyy, m/d/yy, yyyy/m/d, etc. Others may work too, such as Jan 4, 2000 or 15 january, 1926, or 4-2-65, or Thurs Dec 12, 42.

 
----------------------------------------------  
global function Parse(atom ctl, object cal) -- 
---------------------------------------------- 
object date_in = get(ctl,"text") -- save for error msg; 
boolean twodigityear = TRUE 
 
object x = split_any(date_in," ,/")  
  x = pad_tail(x,3,"") 
  for i = 1 to 12 do  
    for j = 1 to 3 do 
	if length(x[j]) > 2 and to_number(x[j]) > 0 then twodigityear = FALSE end if 
        if match(month_abbrs[i],proper(x[j])) = 1 then  
	 x[j] = sprintf("%d",i) 
	end if 
    end for  
  end for 
 
x = join(x,"-") 
 
cal = unpack(cal) -- get target calendar; 
 
object dt = datetime:parse(x,"%m %d %Y") 
 
  if atom(dt) then dt = datetime:parse(x,"%d %m %Y") end if 
  if atom(dt) then dt = datetime:parse(x,"%Y %m %d") end if 
  if atom(dt) then  
     set(ctl,"text",date_in & " <= ERROR") -- show orig input; 
     set(ctl,"color=red,overwrite mode=TRUE") 
     set(ctl,"select region",1,-1) 
     return -1 
  else 
     if twodigityear then dt[1] += 1900 end if 
     set(ctl,"color=black,overwrite mode=FALSE") 
     set(cal,"date",dt) 
     set(ctl,"text",datetime:format(dt,"%m/%d/%Y")) 
  end if 
 
return 1 
end function 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu