CustomField Date Fields
From MovableType
Contents |
CustomField DateFields: Date Formats
The problem
The Custom Fields ("CF") addon bundled with the Professional Pack does not permit you to specify a particular date format. The following modifer has no effect:
format="%m/%d/%Y"
No matter what you do, the CF date is always returned in the "language-aware standard date representation".
MT took over the plugin from Arvind Satyanarayan when it was still in beta. At that time, this problem had been pointed out on the Movalog forums, and Arvind released an update that corrected the problem. The correction does not seem to have been migrated into the Professional Pack.
Identifying the source of the problem
The error seems to be in the code in the CF file ContextHandlers.pm. In a standard MT Commercial installation, this file is to be found at:
mt/addons/Commercial.pack/lib/CustomFields/Template
The error is in lines 169 through 175 of the code in this file. I'm no expert in coding, but, as I read it, the code freezes the date and time formats.
Solution and workaround
Open the ContextHandlers.pm file and comment out lines 169 to 175 (using a # and space mark at the start of each line). The commented out lines should look like this:
# if ('datetime' eq $field->options) {
# $args->{format} = '%x %X';
# } elsif ('date' eq $field->options) {
# $args->{format} = '%x';
# } elsif ('time' eq $field->options) {
# $args->{format} = '%X';
# }
Now you can use any of the standard date format specifiers to your CF date field tags and they render correctly.
Caution: The above hack will force you to specify a format attribute for custom date fields. A patch supplied in the bug report allows the format attribute to remain optional. --Arvind 14:04, 3 September 2008 (UTC)
Possible extension
With this it should be possible to port to MT4.2 the brilliant date tags plugin by Kevin Shay.
I've written to MT about this before, but it's evidently low on their priority list. Kevin's plugin is incredibly useful—you can use it to generate all entries that fall within a range of dates, for example, or to limit a listing to entries of a particular date.
You can also use it to auto-expire posts by comparing the current date to a special CF EntryDataExpiryDate custom date field that you can create. If the current date is after the CF date, the post doesn't show. Beauteous!
--Gautam Patel 04:36, 1 August 2008 (PDT)