Day of the week problem
splash112 - January 3, 2009 - 13:00
| Project: | Simplenews Digest |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | minor |
| Assigned: | Unassigned |
| Status: | active |
Description
If I set my weekly mails to go out on Monday, they will actually be sent on Sunday. Setting the day to Tuesday will sent them out on Monday.
Don't now where this very minor bug is coming from, but my gut feeling tells me it has something to do with the first day of the week, which I set to monday in Drupal.
Any other ideas?
Mark

#1
So the emails are getting sent out a day early or 6 days after they should be getting sent out?
#2
Also, what is your hour setting set to?
#3
A couple of more pieces of information, please. Provide the times the mails are actually sent and how frequently your cron jobs run and your timezone setting. So, to summarize, I'd like to know:
1) What hour the newsletter is scheduled to be sent
2) What hour is actually gets sent
3) Your timezone setting on the site
4) Whether mail is getting sent a day early or 6 days later.
#4
Hi Steve,
Thanks for the quick response, going to investigate (tomorrow). It's almost 1:35 am here. ;-)
Mark
#5
My settings:
Digest:
Sending: Weekly
Day of the week: Monday
Time: 09:00
Site:
Timezone GMT +0100
First day of the week: Monday
Digest message:
Newer nodes created between Jan 3, 2009 06:23:54 pm and Jan 4, 2009 08:59:59 am will be sent out on a cron run per the settings below.
As you can see, everything works flawless, except that Jan 4 is a Sunday. (don't worry about the januari 3 part, That should be alright later on, just messed up some with testing, but the same without the testing happend before.)
#6
Fixed in latest Drupal 5 version.
#7
#8
You beat me to it ;-) Thanks!
While chasing this small bug, I also found some other unexpected behavior: Digest cycling through 2008 just after New Year. In the patch some code to correct that and the weekday problem you already tackled.
Weekly digests should work in this one, daily digests are also patched but not tested.
#9
Heh, I actually found that bug tonight, too! I already patched it in the last release but just for the weekly calculation. I missed the bug in the daily calculation. I'll fix that up now.
My approach to patching the bug is a little different though. Interesting to see yours. I'm not sure I understand the cycle backward part of your code. I think that could throw things off. In my code, you can go either backward or forward from the $approx time to send next newsletter. I don't want to risk changing that algorithm. It took me a while to figure out.
#10
Bug with emails not getting sent out on correct day still needs to be fixed for d6.
#11
Hi Steve,
Thanks. No rocket science in my code. Let me explain.
Just found it very confusing you switch from seconds to days and back. In my proposed code the while structure will check if the "weekday" of $approx_date_to_send_next day is not the same as the $weekday. If it is not the same (true), it deducts 86400 seconds (1 day) from $approx_date_to_send_next and checks again. In the end they will match and $approx_date_to_send_next will contain the right year, month and day, just not the time. This way will prevent any problems (I hope) with days, moths or years).
while (gmdate('w', $approx_date_to_send_next) != $weekday) {
$approx_date_to_send_next = $approx_date_to_send_next - 86400;
}
This way, a weekly newsletter will always be sent within the coming week, a biweekly newsletter will always be sent in the second week.
Safe, clean and simple and no need for any Happy New Year corrections.
#12
Yeah, there was a method to my madness. I just don't remember what it was. I wish I had commented it better. In the end, I'd prefer not to touch the algorithm without extensive testing.
Thank you very much for your work, though. It's much appreciated.