lua-users home
lua-l archive

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



guys, i obviusly wasnt clear.

i am not comparing to datetimes as a whole.
i dont have to know if now() is between "may/5 from 1pm" and "june/20 up to 5pm"

date-range and time-range are independent each other.

i am working on a scheduler:

while(true)
  -- sleep a while...
  campaign = tell_me_if_a_campaign_must_be_executed(table_campaigns)
end


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

user input is not a problem here, since i write manually the records-vector
my problem is how to compare the os.clock and the fields.

thanks again,




> Date: Fri, 8 May 2009 00:26:00 +0800
> From: keinhong@gmail.com
> To: lua@bazar2.conectiva.com.br
> Subject: Re: how to compare 2 dates - NOW WITH TIME
>
> Diego - Red Baires wrote:
>> [snip]
>> premise:
>> i need to represent a range or dates, and then a range of time.
>> i have a list of records that indicates that an event must be
>> executed only if:
>> a) today is between the fields that indicates a range of dates, and then
>> b) os system.clock is between the fields that indicates a range of hours.
>>
>> (is today between date-A and date-B, if so, is now between 3pm and 4pm?)
>>
>> so i am doing this:
>>
>> -----------
>> between_date_from = os.time({ year="2008", month="01", day="01",
>> hour="00", min="00" })
>> between_date_to = os.time({ year="2009", month="05", day="06",
>> hour="00", min="00" })
>
> On many platforms, this os.time() function which calls the
> platform's equivalent will happily accept 'illegal' values like
> month=13 or day=40. You'd get sorta a 'best guess' value. (Note:
> You supply numbers; strings like "2009" are turned into numbers
> like 2009. You might also not need to supply zero fields like
> min=0, because the function does a best guess.)
>
> Thus validating a date is non-trivial. Also, depending on user
> input, dates are of various precisions. More validation, if your
> application expects certain formats or precisions. Then to be
> precisely precise, you'd also need to accept sec=60 for some
> years, which of course, I think most OS don't deal with a leap
> second in the OS layer. Then there is nntp synchronization. And so on.
>
>> [snip snip]
>> now the problem is how to analize a range of hours, not taking in mind
>> the date.
>> any idea ?
>>
>> "os.time()" does not allow (obviously) an assignation like this:
>> { year="0000", month="00", day="00", hour="17", min="30" }
>
> os.time() on most platforms (POSIX-ish) is the number of seconds
> after the Unix epoch. You can trivially compare and subtract the
> times. The difference is in seconds, which you can then convert
> into anything you like.
>
> If you are in total control of an application, and need a standard
> textual format for date/time, then use ISO 8601 [1](or a subset),
> and make your users use it. Make your program validate ISO 8601
> time formats. Once it validates correctly, common ISO 8601 formats
> like YYYY-MM-DD can also be compared trivially in string form.
> Using the ISO form also avoids ambiguity common with date/time
> formats of different countries. More info in [1], link below.
>
> [1] http://en.wikipedia.org/wiki/ISO_8601
>
> --
> Cheers,
> Kein-Hong Man (esq.)
> Kuala Lumpur, Malaysia


Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy! Try it!