I have used this module on a couple of sites, and it just now came to my attention that it stopped working at some point. I'm not sure if it's when this module was upgraded, or Drupal core was but, no matter what date or time I put in, I get the error: "'unpublish on' value does not match the expected format." The module is using the default date format with no changes and I still get this error. I've looked through the forum and none of the advice seems to work for me. I even tried using the most recent dev version, to no avail. Any help would be much appreciated!

Comments

jonathan1055’s picture

Hi,
A few questions to get things started:
1. What Drupal version are you using?
2. Can you show us a screen shot of the form item when you get the error. In particular, what does it show as the example date format beneath the text entry box?
3. Are you using the popup date calendar or just plain text entry?
4. Do you have scheduled publishing enabled?
5. If the amswer to 4 is yes, then does this error happen for that field too?

Jonathan

lebachai’s picture

Hi Jonathan,

  1. Drupal version: 6.26, Scheduler module version: 6.x-1.8
  2. I have 3 screenshots:
  3. Just plain text entry (see screenshot #2, above)
  4. Yes, I believe so (but if the screenshots show I messed up some kind of configuration, please let me know)
    1. HTH!
jonathan1055’s picture

Title: 'Unpublish on' value does not match the expected format » 'Publish on' value does not match the expected format

Hello,
I think I can see your problem, and I have even replicated it myself. In your first screenshot, when you set the date format in admin/settings, I noticed a rather large gap between the i and the a. I think you have two spaces or more in there. I have just tested that theory, and the code (currently) does not do anything special with spaces, so if you enter the time with only one space between the minutes and the 'am' it complains! I set my format to have two spaces, entered the time with only one space between, and got your error. Then I added an extra space and the time was accepted.

Can you verify that this is the cause of your problem? Obviously we will need to make a slight fix to the code to cater for this, as it is not very user-friendly. Maybe always reduce multiple spaces to one space in the admin format setting, and likewise on the text entry. But first, if you can confirm that this is the fault, at least we know what the cause is.

Jonathan

ps. Fixed the title because it was 'Publish on' not 'Unpublish on' for which you had the problem.

lebachai’s picture

I think you nailed it. I just added the extra space when setting the "Publish on" time, and there was no error. Thanks so much for digging into this one--just another proof that an extra pair of eyes is important. I do hope you'll add something in a future version to check for the extra space but, meanwhile, I believe the module is back in business!

jonathan1055’s picture

Title: 'Publish on' value does not match the expected format » Extra spaces in date format causes 'Publish on' not to match the expected format
Version: 6.x-1.8 » 7.x-1.0
Category: support » bug

That's good.
Instead of adding the extra space when entering the date and time, you could remove the extra space in the admin settings, then you would not need to remember to keep adding it.

We will alter the code to eliminate this little difficulty.

Jonathan

jonathan1055’s picture

Status: Active » Needs review
StatusFileSize
new771 bytes

Here is a patch which adjusts the date format in scheduler_admin_validate() before it is saved. Multiple whitespaces (including tabs and newlines) are replaced by a single space. Just for good measure the value is also trimmed for leading or trailing spaces. The new line is:

  $form_state['values']['scheduler_date_format'] = trim(preg_replace('/\s+/', ' ', $form_state['values']['scheduler_date_format']));

Jonathan

lebachai’s picture

Will try this, thanks!

jonathan1055’s picture

The patch was made against D7 code, but the source for this bit is identical in D6. So it should apply ok, just with a note about offset lines.

jonathan1055’s picture

Hi lebachai,
Did you manage to try the patch? I'm reasonably happy with it, and have tested it with all manner of multiple spaces and tabs, but would be good if Eric or Rick (or anyone) would confirm it works and mark it RTBC.

Thanks
Jonathan

lebachai’s picture

Sorry, I haven't been able to. Perhaps someone else can review it?

rickmanelius’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm this works as expected. Setting to RBTC

rickmanelius’s picture

Status: Reviewed & tested by the community » Fixed
jonathan1055’s picture

Status: Fixed » Active

I was about to create a patch to port this to D6, but it occurred to me that maybe we should also do the same treatment of removing multiple spaces in the values entered by the user. The input value is trimmed, which does half the job of the change we made in #6. But I think we should match the tidying up just like when the admin specifies the format.

This could be done in _scheduler_strtotime() so that:

    $time=_scheduler_strptime(trim($str), $date_format);

becomes

    $str = trim(preg_replace('/\s+/', ' ', $str));
    $time=_scheduler_strptime($str, $date_format);

What do you think?

jonathan1055’s picture

Status: Active » Needs review
StatusFileSize
new467 bytes

Here is a patch which makes the additional change in #13.

jonathan1055’s picture

Status: Needs review » Reviewed & tested by the community

I know it is bad form to mark one's own patch as tested, but the additional change in the patch in #14 is really exactly the same as the change already committed in #12

No-one else around here is doing any testing and I really want to get some of these 'needs review' issues ready for the next batch of commits. The open issue queue is now down to 50, the lowest it has been for a few years. At least we can now see all issues on the one page :-)

Jonathan

ericclaeren’s picture

This might be related with this issue, I'm getting an error on submitting the date without a time:

Warning: trim() expects parameter 1 to be string, array given in _scheduler_strtotime() (line 482 of /modules/contrib/scheduler/scheduler.module).

I did apply this patch to test if it might do something with this error but that was not the case.

jonathan1055’s picture

Hi Dreamlabs,

No that is not related to this issue. See #1319410: Fix "warning: trim() expects parameter 1 to be string" when entering date with no time which was fixed in the latest dev version on 27th July and will be in the 7.x-1.2 release.

Seeing as you have applied this patch, could you test and confirm it, please? ;-)

Jonathan

ericclaeren’s picture

Hi Jonathan,

Thanks for your reply, The patch in https://drupal.org/node/1319410#comment-7368706 did work for me. Thanks!

rickmanelius’s picture

Status: Reviewed & tested by the community » Fixed
jonathan1055’s picture

Version: 7.x-1.0 » 6.x-1.9
Status: Fixed » Reviewed & tested by the community
StatusFileSize
new1.16 KB

Given that issue was originally reported in D6, here is a patch for exactly the same fixes as done in #12 and #19 above. The patch is against 6.x-1.9+4 of 28th July.

The fix was confirmed by the original poster, and I have just tested it again, hence marking this RTBC for D6

Jonathan

pfrenssen’s picture

Status: Reviewed & tested by the community » Fixed

Great, thanks! Committed 7cdb376.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.