2

I'm working on a simple event sign up module. The functionality is split in two modules, one which provides an Event content type with title, description and date (from - to) fields, and the second with sign up functionality and sign up window dates for Event content type. The problem is that I don't seem to find a way to properly parse and do comparisons and calculations on the event/signup dates.

Date API documention is quite light on specifics on this area, so it has not been much of a help.

  • How can I use the Date API to obtain DateObject from the event date stored on the node?
  • How can I determine whether the stored event is an all day event?

1 Answer 1

0

How can I use the Date API to obtain DateObject from the event date stored on the node?

Offhand, I'm not 100% sure the right way to do this. It sounds like you want to use the DateObject to perform some calculations -- not just to run through a theme field_formatter. This date issue thread has some code kinda trying to use date fields and their values, but doesnt help much.

Simply because I can understand it (and have used this module myself) I recommend trying out the sub-module of Date, date_api, and an additional 3rd party module: field_extract.

With field extract you can easily (and correctly) access a fields value for instance as a timestamp:

  // Extract from a date, this extracts the first value and provides a
  // formatted date output, uses the specified format, by name.
  $event_timestamp = field_extract_value('node', $node, 'field_event_time', 0, array('format' => 'timestamp'));

You can then use the DateAPI to create a DateObject:

$date = new DateObject($event_timestamp);

How can I determine whether the stored event is an all day event?

Use the date_is_all_day() function found in the date_api module, it compares 2 date fields to check if they encompass a full day.

 function date_is_all_day($string1, $string2, $granularity = 'second', $increment = 1) { ... }
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.