I'm excited to see this project on d.o and can't wait to see it released as a full project. This is a stub issue for notification when that happens. I hope to be able to contribute to the project as well for D7, since this is one of the most common requests I get from site administrators using my install profile. Who knows, maybe I'll even sign up to be co-maintainer. :)

Comments

othermachines’s picture

Thanks, @dnotes! Wanted to get a 7.x version underway to hopefully expedite path to full project. I'm happy to say I've just added a 7.x-1.x branch that is ready for testing.

Edit:

Link to branch: http://drupalcode.org/sandbox/othermachines/1456552.git/tree/refs/heads/...

chiebert’s picture

Hey - Just found this today, and it's working nicely for me on D7 with Date 7.x-2.6. I haven't done anything with customising the theming of the repeat format, but it's nice that you've put those pieces in place. This really helped me out in response to #1401688: How do I make the node view of a repeating date event only show the specific date of the instance I'm viewing..

othermachines’s picture

I confess I keep putting that off, thinking that the folks over at Date module will be fixing this Any. Moment. Now. But since it's been 2-3 years since I first wrote my own fix, I guess I should look at putting it out there.

Spurred on by @chiebert's post, I spent a bit of time assessing the state of the module late last week. It needs work. More like an overhaul. It does way too much unnecessary heavy lifting, which makes it vulnerable to even the smallest code changes in Date API and Date Repeat API.

I've already started on a new version that doesn't create a new formatter but hooks into existing formatters, and only when repeating dates are at play. The purpose of this is to allow Date API and Date Repeat API to take care of the bulk of the output processing, leaving this module to do only one thing -- prettify the repeat output.

I'll likely be renaming the module in order to conform to other modules that hook into formatters. Kind of a pain, I know, but I foresee that someone will bring that up during the release review. That'll mean opening up a separate sandbox.

I'll hopefully have a first version up by the end of the week. I'll keep everyone posted on this thread.

Cheers and thanks for your input -

othermachines’s picture

StatusFileSize
new65.26 KB
new45.08 KB

A couple of screenshots showing how the new formatter settings would look. There is no longer a separate formatter; instead we hook into any formatters of type 'date_default' where the field is a repeating date field. "Expanded" and "Condensed" become "Full" and "Teaser".

Screenshot 1

Screenshot 2

chiebert’s picture

Looks good - I agree it's best to use native date.module functions/methods where possible. As long as this remains a good solution for #1401688: How do I make the node view of a repeating date event only show the specific date of the instance I'm viewing., which has been a royal PITA: if there's only one date, show it; otherwise, show the logical one (last one if all dates have passed, or next one if there are still more to come...).

othermachines’s picture

@chiebert Agreed 100%. I'd like the output to remain pretty much the same, just maybe simplify the theme functions a bit.

aquaseal’s picture

after hours and hours of trial and error and searching around I came across your code. It sounds like a dream come true and I cannot wait to try it out! This will help the date module immensly as I am sure there are plenty of unspoken people out there scratching their heads (or giving up) on displaying the closest date to now in a repeating date. Looknig forward to this module, thanks!!!

othermachines’s picture

Thanks, @aquaseal. I hope it works out for you. Come back and let us know what you think.

aquaseal’s picture

i used this module tonight and everything just worked as expected out of the box! great job @othermachines. One feature request that may be beneficial would be to show the "edit" and "delete" links when using the the date repeat instance module:
http://drupal.org/project/date_repeat_instance

i will implement a work around for a single block that will simply print the date formatted field using the Date and time format to get the links back for easier management.

othermachines’s picture

Thanks for the feedback, @aquaseal. Would you mind opening a separate issue for the feature request? I'll have a look as soon as I'm finished revamping the current code.

lias’s picture

Issue tags: +Date Repeat, +formatter, +node display
StatusFileSize
new7.27 KB

Thank you chiebert for pointing me in this direction and thank you to othermachines for providing this much needed module! I have installed it on a development site using Drupal 7.22, Calendar 7x-3.4, Date 7x-2.6+2-dev and I am so thrilled with the output. I have used the expanded format to display the repeating date and it worked just as you stated in the read me.

I will be installing it shortly on a production machine since I seriously need this function, and it's hard to believe that it's a feature request at the Date module. I'm attaching the zipped of version of your module for those who might have problems with the sandbox download.

Thanks and I will be back!

othermachines’s picture

Thanks a lot, @Isabug.

Update: still working on that revamp talked about in #3. Been very busy. I could use a few more hours in each day. :/

Mark Nielsen’s picture

othermachines, you're a superstar.

On one hand, it does seem odd this isn't provided out-of-the-box with the main Date module. It doesn't seem like a particularly unusual use-case. But given that Date does have this deficiency, I'm so grateful you've done all this work. You've helped me out massively on the project I'm working on, and I think this makes Date Repeat actually fit for purpose.

Thank you :)

othermachines’s picture

Thanks, Mark! Glad I could help.

squarecandy’s picture

Yes, #1509984: Release as full project looks like there's a working solution, and #3 and #4 look promising.

For now, I decided to do it at the theme level:

function THEME_preprocess_field(&$variables) {
	if($variables['element']['#field_name'] == 'field_MY_DATE_FIELD') { 
		if (isset($variables['element']['#items'][0]['rrule'])) {
						
			$rrule = array();
			$rules = explode(';', str_replace('RRULE:', '', $variables['element']['#items'][0]['rrule']));
			foreach($rules as $rule) {
			  $parts = explode('=', $rule);
			  $rrule[$parts[0]] = $parts[1];
			}
					
			$from = strtotime($variables['element']['#items'][0]['value'].' UTC');
			if (isset($variables['element']['#items'][1]['value'])) {
				$seconddate = strtotime($variables['element']['#items'][1]['value'].' UTC');
			} else {
				$seconddate = strtotime($variables['element']['#items'][0]['value'].' UTC');
			}
			$to = strtotime($rrule['UNTIL']);
			$from_month = date('F', $from);
			$to_month = date('F', $to);
			$from_year = date('Y', $from);
			$to_year = date('Y', $to);
			$date = '';
		
			// DAILY display
			if ($rrule['FREQ'] == 'DAILY') {		  
			  if ($rrule['INTERVAL'] == 1 && !isset($rrule['BYDAY'])) {
				$date .= t('Every Day at @time',array('@time' => date('g:i A', $from)));
			  }
			  elseif ($rrule['INTERVAL'] > 1 && !isset($rrule['BYDAY'])) {
				$date .= t('Every @interval Days at @time',array('@interval' => $rrule['INTERVAL'], '@time' => date('g:i A', $from)));
			  }
			  else {
			    $date .= t('Recurring Event');
			  }
			  // $variables['items'][0]['#markup'] = $date;
			}
			
			// WEEKLY display
			if ($rrule['FREQ'] == 'WEEKLY') {
			  if (isset($rrule['BYDAY'])) {
			    $weekday = date('l \a\t g:i A', $seconddate );
			  }
			  else {
				$weekday = date('l \a\t g:i A', $from);
			  }
			  
			  if ($rrule['INTERVAL'] == 1) {
				$date .= t('Every @day, ',array('@day' => $weekday));
			  }
			  elseif ($rrule['INTERVAL'] == 2) {
				$date .= t('Every Other @day, ',array('@day' => $weekday));
			  }
			  else {
				$date .= t('Every @interval Weeks, @day, ',array('@interval' => $rrule['INTERVAL'], '@day' => $weekday));
			  }
			  
			  if ($from_year == $to_year) {
				// Same year.
				if ($from_month == $to_month) {
				  // Same month.
				  $date .= date('F jS', $from) . ' - ' . date('jS, Y', $to);
				}
				else {
				  // Different months.
				  $date .= date('F jS', $from) . ' - ' . date('F jS, Y', $to);  
				}
			  }
			  else {
				// Different year.
				$date .= date('F jS, Y', $from) . ' - ' . date('F jS, Y', $to);
			  }
			  
			}
			
			// MONTHLY display
			if ($rrule['FREQ'] == 'MONTHLY') {
				
			  if (isset($rrule['BYMONTHDAY']) && $rrule['INTERVAL'] == 1) {
			    $date .= t('Monthly on the @day',array('@day' => addOrdinalNumberSuffix($rrule['BYMONTHDAY']) ) );
			  }
			  elseif (isset($rrule['BYMONTHDAY']) && $rrule['INTERVAL'] == 2) {
			    $date .= t('Every Other Month on the @day',array('@day' => addOrdinalNumberSuffix($rrule['BYMONTHDAY']) ) );
			  }
			  
			  if (isset($rrule['BYDAY'])) {
				$weekday = date('l', $seconddate );
				$time = date('g:i A', $from );
			    $plusminus = substr($rrule['BYDAY'], 0, 1);
				$num = substr($rrule['BYDAY'], 1, 1);
				
				if ($plusminus.$num == '-1') {
					$date .= t('Last @weekday of the Month',array('@weekday' => $weekday ) );
				}
				else {
					$date .= t('@day @weekday of the Month',array('@day' => addOrdinalNumberSuffix($num),'@weekday' => $weekday ) );
				}	
				
			  }
			  
			}
			
                        // Show the next upcoming date in the series if there is one.
			foreach ($variables['element']['#items'] as $item) {
				if (strtotime($item['value']) > strtotime('now')) {
					$date .= '<br/>Next: '.date('F j - g:ia',strtotime($item['value'].' UTC'));
					break;
				}		
			}
			
			if (!empty($date)) {
				$variables['items'][0]['#markup'] = $date;
			}
		
		}
	}
}
bkosborne’s picture

Issue summary: View changes

Aren't there issues with caching that aren't considered here? If you're hiding past dates based on the current date from PHP, it will only work if the page cache entry for that node is cleared very often.

othermachines’s picture

Thanks for the note @bkosborne. It's my understanding that the output of hook_field_formatter_view() (which is used here) is outside of the scope of the page cache. If caching is desired, a cache_get/set would be required. I'm not 100% certain - it's been a little while since I've looked at this code - so feel free to correct me if I'm wrong.

othermachines’s picture

Status: Active » Closed (won't fix)

Decided a theme-based approach to the repeating dates problem is still needed, but this module is overkill. I've created a new sandbox over here: Date Repeat Themeable. Its primary purpose is to make repeating dates more themeable with minimal interference with Date module's usual processing. Your participation and feedback is welcome!