CVS edit link for tstoeckler
I have written a simple utility module which provides a block showing the current time. The time zone and date formats (it requires Date API and Date Timezone (
http://drupal.org/project/date)) are configurable through the block configure UI.
I am aware of the World Clock module (
http://drupal.org/project/worldclock) but have personally come to the conclusion that that module solves a different use-case, therefore I did not try to contribute to World Clock but wrote my own module. Even though a super-abstracted Clock module is theoretically possible, I find a simple block showing the time is a common enough use-case to provide a drop-in-and-it-works solution for.
The module is fully functional at this stage, though if this gets accepted plans include SimpleTest coverage and some JS-magic.
Comments
Comment #1
tstoecklerHere is the module and a screenshot of the block configure screen.
Comment #2
tstoecklerHow did that file sneak in there...
Comment #3
sunOverall, this module almost looks too small to deserve an own project.
However, considering that this is a trivial use-case and there may be demand for it, this looks ok - although there are some localization issues with strings in t().
The block rendering function clock_content() should be a theme function and get the display settings already prepared as settings array.
Additionally, I expected some jQuery/JavaScript that updates the clock on the page (optionally / configurable). Probably a good target for future development.
Another possible enhancement in the future would be to support clock "widgets", i.e. JavaScript/Canvas/Flash-driven graphical elements (instead of text).
I'd also like to see an open communication and collaboration with the wordclock module maintainer(s).
Furthermore, I'd be interested to see a kind of "mini-widget" that could be exposed to Administration menu (admin_menu), so one could display a small clock in the menu.
Comment #4
sunAlso, there are plenty of coding style and coding standards issues. Please run this code through Coder and alternatively the coder_format script.
Comment #5
tstoecklerThanks for the quick review!!!
1. t(): I had thought it would be better to wrap the whole thing, including the variables in one t(), but then coder threw up some errors, so I fixed that. Will change depending on what's the right way. Will have a look at some localization documentation, which I admittedly haven't done yet.
2. theme function: Have no clue how to do this, will look into some docs.
3. jQuery to update the clock: Definitely a must have, I thought I would get by without it initially :)...
4. Graphical widgets: See 2. I like the idea, though.
5. Contact the world clock maintainers: Will have a look at exactly what the World clock module does behind the scenes and then submit an issue there.
6. admin_menu integration: See 2. If I've gotten this far, though, should be doable...
By the way, in the version I uploaded, the if statements are constructed wrong, so the forms don't show properly depending on the settings.
Fixed that. Uploading simply for sake of completeness.
So I've got enough to do now, so, depending on the outcome of 5., either see you in 2 months or bye bye!
Comment #6
tstoecklerOh, also:
I ran this code through Coder (and got no errors...), so if you can tell me how you got those errors, that'd be great.
Thanks.
[edit: forget about it. found the coder_format script (great stuff!!!) and applied it. I think that's what you meant. I didn't attach a new version, I'll just remember to run that script beforehand next time.]
Comment #7
avpadernoUse a placeholder.
This is a minor optimization, but the code should be rewritten, as one value excludes the other.
It would also be better to use integers for that setting, as the setting values are part of a set.
What reported by sun about the theme function is still true.
Comment #8
avpadernoComment #9
sun@tstoeckler: I know that you are an active member of the Drupal community... can I trust you and we simply move forward here or do you want to be on the safe side of life and go with us through this process to make sure your CVS stuff has a value for users in the end? :)
Comment #10
tstoeckler@sun: I like being trusted. Thanks.
Actually I was just about to write a little note, in which I would have proposed to not make this issue reliant on a possible collaboration with the Worldclock module, as when I was looking into that module, I realized, quite simply, that Worldclock, to deliver its specific use-case needs to be able to set up multiple times in one block, which is not feasible with just the block-config UI; on the other hand, not using the block config UI for the simple module I wrote but inventing an own one, defeats the whole purpose of being a "simple" utility module. Good that I don't have to make that argument now :)
Also: Done 1. Will start 2 today (and hopefully also finish 2 today) and then prepare for becoming a jQuery-master in 3. and 4. which will probably take me a while, though.
Comment #11
tstoecklerWhile this is still pending: Attaching a new version.
1. Done. I used the placeholders in the t() function.
2. I implemented a theme function. It was the first time I did this, so let me know if I did something wrong. It does still work, though, I tested that. While I was at it, I also surrounded the clock with a span class="clock".
From #7:
I changed that into a switch statement, which makes it look much nicer. Is that what you meant?
Also changing status, as per #9 ?!
Comment #12
avpaderno@tstoeckler: The applicant is not surely the person who can change the status to .
I don't see anything wrong in the code, except I don't understand why it loads data from the other module database table, when it could use
date_api_date_formats(); there are date formats that are not found in the database.Comment #13
tstoecklerRe #12.
Sorry, I suppose I misinterpreted #9.
I didn't use
date_api_date_formats()because I did not see a way to get only the custom formats. I do not want to get all formats, because I want to display the preferred "short", "medium" and "long" formats the user has set on /admin/settings/date-time. Otherwise those settings are kind of worthless.Really? Could you elaborate on that? Because if I use Date API's nice admin UI for custom date formats, they all show up nicely in the {date_formats} table.
Thanks for being so perseverent, I'm still learning all these things...
Comment #14
sunThose theme function arguments should match. The keys specified in the registry should map to the function argument variable names. Furthermore, I think (!) you do not need to specify default values, because theme() will already assign them according to the theme registry. (However, it's possible that this is a D7-only feature, so please test...)
Those cases are missing break; statements - which means that the last ('3') will always be in effect.
You likely want to convert this into a DIV.
You can directly invoke the theme function from hook_block().
However, the rest of the code looks just fine, and we are not really here to teach best practice coding, just prevent horrible code from hitting CVS contributions. Thus, I'll move forward and mark this fixed.
Comment #15
tstoecklerThanks.
Now let's get this baby into CVS!
Comment #18
avpadernoI am giving credits to the users who participated in this issue.