lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Diego - Red Baires wrote:
[snip]
table_campaigns have this definitions

record 1
  this_campaign_applies_from_date = may/6/2008
  this_campaign_applies_up_to_date = jun/20/2009

  this_campaign_applies_on_this_time = 1pm
  this_campaign_applies_up_to_this_time = 2pm

record [n] ...

function tell_me_if_a_campaign_must_be_executed() must
loop into the table, read it records and analize field decribed above.

so, first it compares if today is between the date-ranges of the record,
if so, then it must compare if this clock-time is between the time-range of the record

And os.time() has everything you need, like we said before.

Example. Midnight of 2009-05-01:

os.time{year=2009,month=5,day=1,hour=0,min=0} -> 1241107200

Day of 2009-05-01 will range from: 1241107200 to
(1241107200 + 24*60*60 - 1) or 1241193599

Verify:
os.time{year=2009,month=5,day=1,hour=23,min=59,sec=59} -> 1241193599

The next day:
os.time{year=2009,month=5,day=2,hour=0,min=0,sec=0} ->
1241193600

Within say 2009-05-01, you want 1pm to 2pm:

os.time{year=2009,month=5,day=1,hour=13,min=0} -> 1241154000
os.time{year=2009,month=5,day=1,hour=14,min=0} -> 1241157600

Then your timing range for that day, 2009-05-01 is from 1241154000 to 1241157599

So it does looks like os.time() solves your problem. You only need to parse your input file properly and ensure that the values for each part of each date is valid, mix and match date/time portions accordingly, then compare results from os.time().

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia