I am designing a test site in ProsePoint, and I would like for times to display as a.m. and p.m. instead of the PHP default of am and pm.
I did some research online about this a few weeks ago, and I stumbled across some script or bit of freeware that someone had written for just such a purpose ... but now I can't find it again.
And even if I did ... I'm not quite sure where in the ProsePoint/Drupal installation I might need to put it in order for it to work.
Any ideas or suggestions?
(As always, bear in mind that my knowledge of PHP is minimal at best; I have bought a couple of books, which I am starting to read through, but I feel like I'm still in the "learning my ABCs" stage ... definitely not fluent in PHP yet.)
Comments
More info...
Depending on where you'd like to make the adjustment the solution will be different. Are you after changes in a form or the output on a specific page, etc. Please send a screenshot of what you'd like to adjust. Once the details of the target are clear we can then walk you through some possible solutions. This might also help you in where you choose choose to ask your questions. I suspect that this is going to be more about theming or form over-rides than Newspapers :)
You should also know that while knowledge of PHP is needed there is also a need to understand Drupal's framework to make the kind of change you're after. Effectively this is a project that would be a challenge for anyone who's just starting their efforts with Drupal.
Be brave, we'll get you through :)
Mostly concerned with what the end user sees
Here's a link to the test site: http://localnews.polestarstudios.com/
I have the site set up so that stories display a time field (I used the "Date and time" page to set up a custom date display that only displays the time, then added a "Time" field to the Story node). That field is visible to the end user on the story page, the front page, and any of the channel or edition pages. That's where I'd like for the time to display in a.m./p.m. ... because it's proper AP style (I'm an English major who ended up doing design to pay the bills).
So it's not a matter of just one page; it's any time that a time is displayed to the end user.
I don't mind if the forms that the reporters and editors see (when they're creating or editing a story) use the PHP format of am/pm ... as long as it's understood that it will display in the story (or teaser) in correct AP style once it's visible to the end user.
And yes, I wasn't sure where to post this question; I looked through the list of groups, but it wasn't clear to me where would be the best place to post the question. So I decided to post it here, figuring that if I'm completely off, maybe someone can point me in the right direction.
(It might be helpful to have something available on the Drupal site to help novices like myself figure out where to go with certain types of questions.)
Katrina
Site builder, writer, trainer, graphic designer
Let's start from here...
K.,
For starters I'm not going assume anything about your knowledge level so please let me know if my explaination/direction does not provide enough depth. My goal with all of these types of threads is a reference that others can stumble upon later to help them as well.
Let's start from here: http://localnews.polestarstudios.com/story/sample-news-story-1. This is a basic node of the type "story" generated with a template file.
Step 1. In your theme folder, please post a list of all the files ending in ".tpl.php".
Step 2. There should be a file called node.tpl.php. Copy this file and rename it node-story.tpl.php
Step 3. Post a copy or screenshot of the source (HTML code) of this file.
I'll post further steps/questions once this information is available. I hope you don't mind a little back and forth.
Back and forth .. not a problem
Side note: I'm building this test site to iron out as many problems as I can before tackling the actual design of the new site for the newspaper where I work; the corporate "powers that be" have agreed to Drupal, but it's not clear yet whether they'll let me use ProsePoint specifically or if they have their own Drupal setup (our newspaper is going to be a test case for using Drupal; if we're successful, I may be sharing what I learn with a lot of other newspapers owned by the media syndicate). I'll find out for certain during Monday's conference call.
So I'm trying to keep track of the changes and adaptations I'm making, so I can transfer them over to the new site (once I start building it) and shorten my learning curve.
So I may be notating some things for myself during this discussion so I can refer back to them later. Example: Note to self: I'm using a sub-theme in ProsePoint, so while the CSS file in the sub-theme folder controls the look of the site, the .tpl.php files are actually in the tma2 folder inside profiles/prosepoint/themes/tma2.
Note to self: There is an extra .tpl.php file in that folder already; I created it to remove the colon for the label for the "stories" field in the Edition content type so that the heading of the "Other stories" section on the front page doesn't have a colon.
.tpl.php files in the tma2 theme folder:
-> channel-subblock.tpl.php
-> content-field.tpl.php
-> content-field-field_stories.tpl.php (the custom file I created)
-> maintenance-page.tpl.php
-> node-story-teaser.tpl.php
-> node-story.tpl.php
-> node.tpl.php
-> page.tpl.php
Since there is an existing node-story.tpl.php file, here's the code:
<div class="node <?php print $node_classes; ?>" id="node-<?php print $node->nid; ?>"><div class="node-inner">
<?php if ($page == 0): ?>
<h2 class="title">
<a href="<?php print $node_url; ?>"><?php print $title; ?></a>
</h2>
<?php endif; ?>
<?php if ($unpublished): ?>
<div class="unpublished"><?php print t('Unpublished'); ?></div>
<?php endif; ?>
<?php if ($picture) print $picture; ?>
<?php if ($submitted): ?>
<div class="submitted">
<?php print $submitted; ?>
</div>
<?php endif; ?>
<?php if (count($taxonomy)): ?>
<div class="taxonomy"><?php print $terms; ?></div>
<?php endif; ?>
<div class="content clear-block">
<?php print $content; ?>
</div>
<?php if ($links): ?>
<div class="links">
<?php print $links; ?>
</div>
<?php endif; ?>
</div></div> <!-- /node-inner, /node -->
Katrina
Site builder, writer, trainer, graphic designer
Next step - break $content down
Based on your code above, the date appears to be coming out of $content.
Please edit node-story.tpl.php with the following:
<div class="content clear-block">
<pre>
<?php print_r($content); ?>
</pre>
<?php print $content; ?>
</div>
Post the results of the print_r command that will be output on the page right above the existing node content.
?????
Well, I followed your directions; you can see the results on any of the stories on the site, such as this one: http://localnews.polestarstudios.com/story/sample-news-story-4
I don't see much difference, other than throwing off the CSS.
Katrina
Site builder, writer, trainer, graphic designer
localization module
Want to try to use the localization moduleto change the display text with out altering code!
Shyamala
Unimity Solutions
Does that work like string overrides?
Well, I already tried string overrides -- no luck. Does the localization module work on the same principle?
To use any kind of find-and-replace tool, it would have to be pretty specific, because "am" is not just an abbreviation (sans the correct punctuation) for "ante meridiem"; it's also a form of the verb "to be." So I don't want to end up with a sentence such as "I am tired" turning into "I a.m. tired"!
Katrina
Site builder, writer, trainer, graphic designer
Jumping ahead...
K.,
Wonderful that you've already tried "string over rides". I would still like you to provide the results of print_r as we're building a reference document for the community. There's a solution for you at the end of this process but I want this to be of value to others as well. I understand your concerns but the solution I have in mind will be more robust.
Be cautious of using the localization module to do simple output modifications. The load on your server can be quite high as compared to code (PHP) solutions. Effectively the localization module will scan all of the translatable text on your site to do a single text change (am -> a.m.) each time the cache is rebuilt. Seems like a very resource expensive route to take.
Is the print_r not working correctly?
I did the print_r modification you asked for; when I view a story page ( http://localnews.polestarstudios.com/story/sample-news-story-4 ), I don't see anything different, other than a duplication of content and the CSS obviously being thrown way off.
Katrina
Site builder, writer, trainer, graphic designer
My bad...
My bad, try print_r($node);
Aha!
Aha! That makes more sense.
That's a LOT of code; do you want me to copy and paste it all here? Or just certain sections? Or you can view it here: http://localnews.polestarstudios.com/story/sample-news-story-2
Or on any of the story pages, for that matter.
Katrina
Site builder, writer, trainer, graphic designer
Drill down...
Now you have the details of what's available to you for display in your template.
-> Replace <?php print $content; ?> with:
<div class="field field-type-text field-field-subtitle">
<div class="field-items">
<div class="field-item odd"><a href="<?php echo $node->path ?>"><?php echo $node->title ?></a></div>
</div>
</div>
<div class="field field-type-nodereference field-field-source">
<div class="field-items">
<div class="field-item odd">
<a href="node/<?php echo($node->field_source[0]['nid]) ?>"><?php echo($node->field_source[0]['view']) ?></a>
</div>
</div>
</div>
<div class="field field-type-date field-field-date"><?php echo(date("", $node->created)) ?></div>
<div class="field field-type-date field-field-time">
<?php
$displayTime =date("h:i", $node->created));
if (date("G", $node->created) >= 12) {
$displayTime .= 'p.m.';
} else {
$displayTime .= 'a.m.';
}
echo $displayTime;
?>
</div>
bla bla bla...
Let me know if you get the idea as you're now free to call on any of the content found in the node object and format as you see fit.
Enjoy!
Wait a second ...
Rather than completely rewriting the $content for the entire story node, wouldn't it be possible to create an individual content-field-field_time.tpl.php that would have this same effect?
I was able to override the colon following the "Other stories" label in the "stories" field with a custom content-field-field_stories.tpl.php file; can I do something similar with the time field?
Katrina
Site builder, writer, trainer, graphic designer
Need different solution
No, that's not going to work. I tried adding the PHP to a custom .tpl.php file, so it only affects the Time field. But I also left in the original coding, so I could see if the new date format matches the old one (with the exception of displaying a.m./p.m. correctly).
Instead, I get a completely different time that doesn't match the original time at all (even the minutes are wrong, so it's not merely a time zone problem).
I need a solution that allows the Time field to still display correctly; I simply need the am/pm changed to a.m./p.m., not rewriting the Time field, as that sets up all kinds of new problems.
Katrina
Site builder, writer, trainer, graphic designer
Hack the Date API?
I'm wondering if it's possible to hack the Date API. I've been looking at the source code for the .inc files; I noticed that date_api_elements.inc has a list of "case" lines for each of the letters that stands for a particular part of the date/time format. Would it be possible to add something to the "case 'a':" line that would reformat it in a.m./p.m. style?
Or maybe there's some other part of the Date API that could be modified to get the desired result?
Just a thought.
Katrina
Site builder, writer, trainer, graphic designer
It's been done in WordPress
I found a plug-in someone created for WordPress; it would be great to see something like this for Drupal. Here's the part of the code pertaining to a.m./p.m.:
function ap_time() {
$capnoon = get_option('ap_capnoon');
// Format am and pm to AP Style abbreviations
if (get_the_time('a')=='am') :
$meridian = 'a.m.';
elseif (get_the_time('a')=='pm') :
$meridian = 'p.m.';
endif;
// Eliminate trailing zeroes from times at the top of the hour and set final output
elseif (get_the_time('i')=='00') :
$aptime = get_the_time('g')." ".$meridian;
else :
$aptime = get_the_time('g:i')." ".$meridian;
endif;
echo $aptime;
}
Katrina
Site builder, writer, trainer, graphic designer
Four questions...
You've posted four rounds of new questions!! They're all very valid and I encourage you to look into each of them. I suggest you move to the IRC channel if you're looking for these level of feedback or break each into new threads in the theming group.
Some important points:
-> Never "hack" code. There's a mechanish called "hook overrides" that you should look into. Look through the DateAPI module for functions that start with "theme_". These can be used for custom applications in you templates.
-> The code I provided uses the creation timestamp value for the node. I'm not sure what your $content date/time represents. Look through the output from print_r($node) for the other possible time values that you can reformat.
-> Remember there's always five (or more) ways to achieve something in Drupal, none are "correct" or "bad" so long as they fall within some basic guidelines which include "Never Hack Core".
Field_time from print_r($node)
Here are the two sections of code regarding field_time that show up from print_r($node):
[field_time] => Array(
[0] => Array
(
[value] => 2010-01-08T03:15:00
[timezone] => America/New_York
[timezone_db] => UTC
[date_type] => date
[view] => 10:15 pm
)
[field_time] => Array
(
[#type_name] => story
[#context] => full
[#field_name] => field_time
[#post_render] => Array
(
[0] => content_field_wrapper_post_render
)
[#weight] => -3
[field] => Array
(
[#description] =>
[items] => Array
(
[0] => Array
(
[#formatter] => time
[#node] => stdClass Object
RECURSION
[#type_name] => story
[#field_name] => field_time
[#weight] => 0
[#theme] => date_formatter_time
[#item] => Array
(
[value] => 2010-01-08T03:15:00
[timezone] => America/New_York
[timezone_db] => UTC
[date_type] => date
[#delta] => 0
)
[#title] =>
[#description] =>
[#theme_used] => 1
[#printed] => 1
[#type] =>
[#value] =>
[#prefix] =>
[#suffix] =>
[#children] => 10:15 pm
)
[#title] =>
[#description] =>
[#children] => 10:15 pm
[#printed] => 1
)
[#single] => 1
[#attributes] => Array
(
)
[#required] =>
[#parents] => Array
(
)
[#tree] =>
[#context] => full
[#page] => 1
[#field_name] => field_time
[#title] => Time
[#access] => 1
[#label_display] => hidden
[#teaser] =>
[#node] => stdClass Object
RECURSION
[#type] => content_field
[#children] => 10:15 pm
[#printed] => 1
)
[#title] =>
[#description] =>
[#children] =>
10:15 pm
[#printed] => 1
)
And yes, I've posted a thread in the theming group as well.
Katrina
Site builder, writer, trainer, graphic designer
Hi Katrina, I think the best
Hi Katrina,
I think the best way to do this is to override the theme function. If you install the Devel module and enable the Themer Info (I think you need Firefox with firebug - a massively useful add-on anyways) you can see how different bits of the display are created. This is a massive time-saver. I've just had a go on the submitted by bit and saw it was themed by theme_node_submitted. This calls format_date; one solution would be to do a str_replace on the result.
HTH
Andy
Sounds good, but ....
That sounds like a possibility ... but I'd still need someone to walk me through the process. I've been able to make some PHP adjustments -- but only when I found directions online that said, "Do A, B, C, then D." Aside from carefully following directions and occasionally being able to extrapolate from someone else's directions, I am essentially PHP illiterate.
Katrina
Site builder, writer, trainer, graphic designer
No worries, gimme a sec n
No worries, gimme a sec n I'll try and whip something up.
K, I don't know if you're
K, I don't know if you're using your own theme you've created or someone else's. If it's your own work great; if not, you might want to subtheme it and follow these instructions on the subtheme.
function theme_node_submitted($node) {return t('Submitted by !username on @datetime',
array(
'!username' => theme('username', $node),
'@datetime' => format_date($node->created),
));
We want to change that to something like this.
function THEMENAME_node_submitted($node) {
$created=str_replace('am', 'a.m.', $format_date($node->created));
$created=str_replace('pm', 'p.m.', $created);
return t('Submitted by !username on @datetime',
array(
'!username' => theme('username', $node),
'@datetime' => $created,
));
}
Note, so if your theme's called new_theme_v1 the function name would be
new_theme_v1_node_submittedThis is untested, so excuse typos; should work tho.
Hope that helps. Any Qs?
Need an adaptation of this for my situation
The problem with the solutions offered so far is that they're all assuming that the Time field I'm trying to change is using the "created" timestamp. It's not. It's a field in which a timestamp is typed -- "Jan 10 2010 - 8:45pm" -- and all that's displayed to the end user is the time: "8:45 pm".
At any rate, I did install the Devel module and activated it. If I turn on "Themer Info" and click on my Time field, here's what I see:
Parents: theme_date_display_single < theme_date_display_combination < content-field.tpl.php < theme_markup < theme_markup < node.tpl.php < page.tpl.php
Function called:
theme_date_all_day ()
Candidate function names:
news_date_all_day < phptemplate_date_all_day < tma2_date_all_day < tma_date_all_day < zen_date_all_day < theme_date_all_day
After that is the function arguments section, which contains way more information than I can reproduce here.
Does that help any?
Katrina
Site builder, writer, trainer, graphic designer
sorry, sorry, sorry. The same
sorry, sorry, sorry. The same approach can still be used... but could you just let me know if you will want to be translating your site? (you can do it quick n dirty if not;)
Just out of interest, why are you using a Date field for the submitted date? Or have I got the wrong end of the stick?
Why a Date field?
Why a date field? A couple of reasons.
First, in the actual newspaper site, not all stories will go live when they're first created; they may be scheduled for later. So the "created" date might be completely off (by as much as a few days for, say, a Sunday lifestyles story written on Wednesday) from when the story actually goes live to the site.
Also, I'm still experimenting with how things will work on the site (that's why it's a "test" site!). It seemed easy enough simply to put in a date and time, rather than trying to figure out a way to ensure that the date or time that shows up on the story matches the time the story goes live to the site.
And no, I'm not anticipating the need to translate the site. I could be wrong about that -- we do have a growing Hispanic population -- but no one has mentioned to me the need for the site to be translated; I seriously doubt it's something that will be requested any time soon.
Does that help?
Katrina
Site builder, writer, trainer, graphic designer
< p>Solution! < p>You can use
Solution!
You can use stringoverrides and your string is !ampm-abbreviation am|pm|AM|PM going to !ampm-abbreviation a.m.|p.m.|A.M.|P.M.. Tada!
PS that's not the hacky way -
PS that's not the hacky way - I had a dumb idea when I wrote about that. I then realised that if Date was using the translation functions then it should be possible with stringoverrides, and following through the code it turns out that to avoid exactly the problem you originally stated (am is a verb and an abbreviation) the author of Date created large contextful strings which are used by Date to create the final display. If you fancy changing other parts of the date display check out the strings at http://api.lullabot.com/date_t_strings.
Hooray!
That works beautifully. Thank you!
Katrina
Site builder, writer, trainer, graphic designer
String overrides for times generated by Views?
The String Overrides solution provided above works great for the time generated on the node pages themselves and even in the "teasers" on the Edition pages.
However, if I use a View to generate a set of teasers (e.g., the three most recent stories tagged with a certain taxonomy term), the time field displays "am/pm" instead of "a.m./p.m."
Is there any way I can use String Overrides to fix that?
Katrina
Site builder, writer, trainer, graphic designer
< p>Hi Katrina, < p>Realise
Hi Katrina,
Realise this is a bit late... is this still an issue?
Andy
Andy ...
Andy, yes, the latest problem (with Views) is still an issue; if you have any ideas or suggestions, I'm all ears! (So to speak.)
Katrina
Site builder, writer, trainer, graphic designer
Hi, can I just confirm the
Hi, can I just confirm the setup? You have a CCK field from the Date module that uses a custom format for input and display that limits it to just time. The PHP date string you're using is something like
h:i a. You use stringoverrides to change am/pm into a.m./p.m. but it isn't working on (any?) views.It seems rather strange to me. Do you have a link where it's visible? It's definitely the CCK field that's not displaying correctly, and not some other field, or the node creation time? What's the style and row style for your view?
Cheers,
Andy
Maybe the problem is ....
Well, maybe the problem is that I'm not using the CCK "Time" field to populate the "time" field in the View; I'm using the "Node: Updated date" field in Views, custom-formatted as "g:i a".
It might actually work if I replaced that with the CCK "Time" field.
I'll try that.
Katrina
Site builder, writer, trainer, graphic designer
That'll be the problem. The
That'll be the problem. The strings you're overriding are provided by Date. I presume then that Date doesn't override
theme_node_submittedwhich therefore doesn't use Date's functions. I can't tell from your post if the most appropriate value to display is the updated date or the CCK field; if you want the updated date, put the following in your theme's template.php (see comment further up for subtheming tips if necessary).function THEMENAME_node_submitted($node) {return t('Submitted by !username on @datetime',
array(
'!username' => theme('username', $node),
'@datetime' => function_exists('date_format_date') ? date_format_date($node->created) : format_date($node->created),
));
}
This will take advantage of Date's formatting function when available and fall back to the default Drupal function when not. (Not tested.)
HTH
I'll try that
Actually, I do want the "updated date", because the CCK field doesn't change to reflect when the story was last updated.
I'll try what you suggested; it may be next week, as I have several other items on my to-do list for this week that have to take priority.
Thanks for your help!
Katrina
Site builder, writer, trainer, graphic designer
Editing Date output is harder than it sounds
This is a great thread. I want to do more or less the same thing Katrina wants to do - I'd like to apply span classes to various parts of a CCK date field (including the ante/post meridiem) so that I can target them with CSS. I originally tried to do it in a preprocess function, but that's obviously too late in the process. I discovered, as Katrina did, that that only works if you want all your dates to be December 31, 1969, 8:00am EST.
It didn't seem that String Override was appropriate for HTML, so I didn't try that.
Instead I created a "content-field-field_event_date.tpl.php" template with the following code:
<?php if (!$field_empty) : ?><div class="field event-date">
<?php if ($label_display == 'above') : ?>
<div class="field-label"><?php print t($label) ?>: </div>
<?php endif;?>
<?php
$parsed_date = date_parse($node->field_event_date[0]['value']);
$unix_date = strtotime($node->field_event_date[0]['value']);
$monthstr = strftime("%B", $unix_date);
$offset = 4; // where offset == number of hours behind
$twelvehourtimestr = date("g:i", $unix_date-($offset<em>60</em>60));
$meridiemstr = date("A", $unix_date-($offset<em>60</em>60));
print '<span class="month">' . $monthstr . '</span> ';
print '<span class="day">' . $parsed_date['day'] . '</span>, ';
print '<span class="year">' . $parsed_date['year'] . '</span>, ';
print '<span class="time">' . $twelvehourtimestr . '</span> ';
print '<span class="meridiem">' . $meridiemstr . '</span>';
?>
</div>
<?php endif; ?>
You could accomplish the a.m./p.m. piece here with an IF statement replacing am or AM with a.m., etc.
But then I was still left in the same place as Katrina, where I had solved the problem for nodes but not for views. I thought of creating date formats that only showed a piece of the date (just "A", or "g:i", for example), adding the date field to the view multiple times and setting each instance to display a different piece, and using the Semantic Views module to surround each one with the desired span. Problem solved, I think, until I realize that both pieces of this solution only work for a single date - if it's a range it doesn't work. Grr. So I'm back at square one.
The problem with every posted solution I've seen is that they come in too late in the process and override the (necessary) complexities of the date module. It seems to me what we need is a "Semantic Date" (like Semantic Views) module that would insert your desired formatting changes into the Date module output. I don't have the developer skills to do that, but I wish I did.
Any other brilliant ideas? This does not seem like it should have to be rocket science.
Hi, I think part of the
Hi,
I think part of the problem is that there are a number of ways that a date can be themed onto your page.
Normal node rendering
If you render a node normally with the default theming, it will display the user name and creation date, which is themed by
theme_node_submitted(). This exists in a bare install with no contributed modules.Views date handler
Views uses field handlers to manage field display. If the field is a normal date (not a CCK field from date.module) then Views will use the class
views_handler_field_date. You can extend the class to modify how the handler works. For more info check out the Advanced Help pages for Views and the Views API site.Date fields
If you have a CCK field of type Date then its display is handled by a custom handler supplied by Date called
date_handler_field_multiple. This in turn seems to use Date's theming functions (because that's what shows up when you use Theme developer).I don't know of any way to kill the three birds with one stone. I guess you could override
theme_views_view_field()which gives you the view object, the field handler object and the raw SQL row. You could then modify the output for date.module dates, and for normal views field dates; it still wouldn't affect the normal node submitted dates. If it was me I guess I'd override the themes for Date and theme_node_submitted, and extendviews_handler_field_date. I've not done this, and can't promise it's the best way.HTH
Andy
Thanks for the good summary
Thanks - this is a lot of helpful information. I don't mind having to hit the problem several different ways, which is what I've done in the past to solve instances 1 and 2 of your three. It's easy to theme the submitted variable (#1). And I'll need to play around with
views_handler_field_date- in the past I've just dealt with views in the way I described above - adding the date field to the view twice and formatting one to display date only and one as time only, so I could apply separate classes to each - that works fine if you're just looking at a created date and not a date range.But where I got hung up this time was on your third instance - the CCK date field. I just looked at
date_handler_field_multiplebut frankly I have no idea how I would override that or do anything else with it. (I'm a designer/themer so my module developer skills are currently limited to minor hacks and "paste this and add an info file an that's a module"). I find the Date theming functions stuff more accessible, but given how intricate Date is I think I need to get over my obsession with altering the output, at least until I have more time and/or more developer chops.But if anyone has done anything like this and wants to share their snippets, (or knows of a simpler way to attack the CCK Date portion of the problem) I'd love to hear it.
Actually, there might be a
Actually, there might be a way to theme all dates in one fell swoop. You can create a custom date format that includes the relevant HTML escaped. Eg. have a format like this:
\<\s\p\a\n\ \c\l\a\s\s\=\"\m\o\n\t\h\"\>M\<\/\s\p\a\n\>By default Date only allows 100 characters for the format string, but that could easily be overridden in a custom module. I'll see if I can whip something up.
I've created two small
I've created two small modules.
admin/settings/date-time/formats/addso that any HTML tags you enter as part of the format string are automatically escaped (and filtered for security).You can test it with something like
<strong>M</strong>or
<span class="day-name">D</span> <span class="day-number">j</span> <span class="month">M</span> <span class="year">Y</span>I'm not sure how great a way this really is to achieve your goals, except that it actually works, and it doesn't require repeating the same idea three times over as I originally suggested. There may be some places that are expecting plain text from
format_date()and that may cause the HTML to be escaped and become visible. I'm not aware of any situations where this might happen though. It seems to work for me, so give it a go.HTH
Andy
It's even more complicated
Actually, I'm with the O.P. that any time a date is displayed to site visitors whether from a field or view and without regard to what field it is, I want it to appear in Associated Press (AP) style. It essentially would replace the Short, Medium and Long formats with an AP Date. This brings up potential legal issues, as the style is copyright by AP, so I can't fully describe it here and there may be an issue with distributing specific code for the solution.
That is, I'm looking for a generic place that will let me do PHP edits on a string of one or two long-format dates.
So I'm going to describe it in general terms. I'm not looking for the code, I'm looking for where the code would go (without messing with core or an existing module).
The month might or might not be abbreviated depending on which month it is and whether it is a specific date. If it is abbreviated, it would be a specific abbreviation that is not produced by PHP's code for month abbreviation.
There is of course the punctuation of am and pm.
There are two times a day that a word is used in place of the time.
Minutes are not shown for times on the hour.
Additionally, we have an internal style that when giving a date range that includes repeats between the from and to, that we omit the repetition from the from portion. We also omit the current year unless it will cause confusion.
For example (posting this in February 2012):
Wednesday, Sept. 23, 10 to 11:46 a.m.
Wednesday, Sept. 23, 10 a.m. to 2 p.m.
Wednesday, Sept. 23, 10 a.m. to Thursday, Sept. 24, 2 p.m.
Wednesday, Sept. 23, 2012, 10 a.m., to Thurday, March 19, 2013, noon
Thursday, March 19, 2013, noon
which would become when Jan. 1, 2013, hits:
Wednesday, Sept. 23, 2012, 10 to 11:46 a.m.
Wednesday, Sept. 23, 2012, 10 a.m. to 2 p.m.
Wednesday, Sept. 23, 10 a.m., to Thursday, Sept. 24, 2012, 2 p.m.
Wednesday, Sept. 23, 2012, 10 a.m., to Thurday, March 19, 2013, noon
Thursday, March 19, noon
I'm guessing this restricts where I can put the code, and I'm wondering where the hooks would be for me to work PHPs text-editing magic on the long date format.
I'm not looking to insert HTML, just change the visible text.
Charles Belov
Webmaster
San Francisco Municipal Transportation Agency (SFMTA)