I'm in the middle of putting together a social networking website using nodeprofile as a base for user profiles. As part of this project i want users to be able to add their birthdays using a cck date field (month, day, year). In particular i'd like users to only be able to select any year between todays current year and a hundred years ago. Basically i don't want users to make themselves 300 years old or born in the year 2017.
After looking across different forums it seemed to me that the best way to do this was to edit the "Years back and forward:" input on the date field widget settings page. I changed "Years back and forward:" to -100:+0. This worked at first, when a user went to their profile edit page they were presented with a birthday field containing a drop down box with the years 1907-2007. Which is basically what i wanted.
The only problem is that if a user selects their birth year as 1973, the next time that user edits their birth year the drop down box will contain the years 1873-1973. I guess the function -100:+0 in "Years back and forward:" bases itself off of whatever a user inputs after its initial creation.
To be honest i'm not fully sure if this is a bug, if i'm doing something wrong or if "Years back and forward" is intended to function this way. Either way i'd be very grateful to anyone who could point me in the right direction in regards to the functionality i'm looking for.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | date_select_list.patch | 1.37 KB | v1nce |
| #1 | date_admin_select_list.patch | 1.52 KB | v1nce |
Comments
Comment #1
v1nce commentedThe attached patches now allow you to enter 'now' for the forward year, which corrects this issue. This allows you to set the forward year to the current year and subtract the years back value from the current year.
So for the birth date issue above, you would set the "Years back and forward" value to -100:now.
Comment #2
karens commentedA different way of fixing this has gone into the HEAD version, which will soon become the 5.2 version of the Date module. The problem with centering on 'now' instead of the current value in the date is that as you move forward in time, the older values will no longer show up on the list. Say you create a date on the last day of December that is 100 years old, when you move into January, it will no longer show up on the list.
I do agree that centering the list on 'now' instead of the stored date is more logical, but what is needed is a combination -- center the range on the current date, then test if the stored date value falls outside the range, and if so, extend the range to include it.
That's what I've done in the new version.
Comment #3
v1nce commentedCould you expand on what you describe here:
Comment #4
karens commentedYou don't have to do anything, the code is doing it.
If you want to know how the code works, take an example of a year range of -3:+3 (the default). On December 31, 2007 the date range (centered on 'now') goes from 2003 to 2010, and one of your users creates a date for the year 2003. On January 1, that user wants to update the date, but 'now' has changed and the date range goes from 2004 to 2011 and their year is no longer on the list. So my code now compares the year in the field (2003) to the minimum year for the range (2004) and expands the range to include it, so the range becomes 2003-2011 instead of 2004-2011 for this date.
Comment #5
v1nce commentedLooks good. Will entering 0 for the second parameter of the date range pull the current date?
Thank you.
Comment #6
karens commentedExactly. right now (in 2008), -3:+0 would give you 2005-2008. -0:+2 would give you 2008-2010. And so on.
Comment #7
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.