Mailing List Archive

[Bricolage-General] date formatting
All,

We just upgraded to the most recent build of bric, and prior to that we were
using local_date() to format bric date strings, like this:

if (my $pubdate = $element->get_data('publication_date')) {
$formatted_date = local_date($pubdate, "%B %Y");
}

However, now get_data on a bric date field no longer returns an ansi date
string, it returns a typically formatted date string: Month Day, Year. Is
there any way to change what kind of date string is returned, or should I
just parse the new date string and get what I want.

Phil


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Bricolage-General mailing list
Bricolage-General@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bricolage-general
Re: [Bricolage-General] date formatting [ In reply to ]
On Monday, September 23, 2002, at 08:24 AM, Philip Fibiger wrote:

> However, now get_data on a bric date field no longer returns an ansi
> date
> string, it returns a typically formatted date string: Month Day, Year.
> Is
> there any way to change what kind of date string is returned, or
> should I
> just parse the new date string and get what I want.

There are two ways. You can a) change the date formatting preference,
or b) pass in a strftime format string to get_data(). The date will be
returned in your local time zone.

HTH,

David

--
David Wheeler AIM: dwTheory
david@wheeler.net ICQ: 15726394
http://david.wheeler.net/ Yahoo!: dew7e
Jabber: Theory@jabber.org



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Bricolage-General mailing list
Bricolage-General@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bricolage-general
RE: [Bricolage-General] date formatting [ In reply to ]
David,

That local_date() call was commented out in my actual code, when I pasted it
into the email and neatened it up, I accidentally uncommented it. The code
actually looks like this:

if (my $pubdate = $element->get_data('publication_date', "%B %Y")) {
$formatted_date = $pubdate;
}

Doing this, it prints nothing. If I remove the arg for the time format, it
works fine printing Month Day, Year. Does the bric time format need to be
set a particular way (ISO?) for the formatting argument to work?

Phil

-----Original Message-----
From: David Wheeler [mailto:david@wheeler.net]
Sent: Monday, September 23, 2002 4:33 PM
To: Philip Fibiger
Cc: bricolage-general@lists.sourceforge.net
Subject: Re: [Bricolage-General] RE: date formatting


On Monday, September 23, 2002, at 03:31 PM, Philip Fibiger wrote:

> I looked through Data.pm in /Bric/Biz/Asset/Business/Parts/Tile and
> saw the
> added code for date formatting, but when I try to grab a formatted date
> string like this:
>
> if (my $pubdate = $element->get_data('publication_date',
> $format_string)) {
> $formatted_date = local_date($pubdate, "%B %Y");
> }
>
> the get_data returns nothing, and doesn't return an error, as far as I
> can
> tell. Any ideas about what i'm doing wrong?

Not offhand, but I *can* tell you that you don't want to call
local_date(). get_data() does that for you. So you can just do this:

my $formatted_date = $element->get_data('publication_date', "%B %Y");

HTH,

David


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Bricolage-General mailing list
Bricolage-General@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bricolage-general
Re: [Bricolage-General] date formatting [ In reply to ]
On Tuesday, September 24, 2002, at 10:00 AM, Philip Fibiger wrote:

> Doing this, it prints nothing. If I remove the arg for the time
> format, it
> works fine printing Month Day, Year. Does the bric time format need to
> be
> set a particular way (ISO?) for the formatting argument to work?

No. If you don't pass in the date format argument, it just looks up the
Time/Date Format preference and uses that.

What happens when you use a different date format, say "%D"?

David

--
David Wheeler AIM: dwTheory
david@wheeler.net ICQ: 15726394
http://david.wheeler.net/ Yahoo!: dew7e
Jabber: Theory@jabber.org



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Bricolage-General mailing list
Bricolage-General@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bricolage-general
RE: [Bricolage-General] date formatting [ In reply to ]
David,

No luck, I tried a few different date formats, and still nothing. Changing
the date/time format in bric does work correctly.

Phil

-----Original Message-----
From: David Wheeler [mailto:david@wheeler.net]
Sent: Tuesday, September 24, 2002 10:42 AM
To: Philip Fibiger
Cc: bricolage-general@lists.sourceforge.net
Subject: Re: [Bricolage-General] date formatting


No. If you don't pass in the date format argument, it just looks up the
Time/Date Format preference and uses that.

What happens when you use a different date format, say "%D"?

David


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Bricolage-General mailing list
Bricolage-General@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bricolage-general
Re: [Bricolage-General] date formatting [ In reply to ]
On Tuesday, September 24, 2002, at 11:06 AM, Philip Fibiger wrote:

> No luck, I tried a few different date formats, and still nothing.
> Changing
> the date/time format in bric does work correctly.

Does the get_data() method look like this for you?:

sub get_data {
my ($self, $format) = @_;
my $sql_type = $self->_get_sql_type or return;
return $sql_type eq 'date' ?
local_date($self->_get('_date_val'), $format) :
$self->_get('_'.$sql_type.'_val');
}

If so, try this instead:

sub get_data {
my ($self, $format) = @_;
my $sql_type = $self->_get_sql_type or return;
return $sql_type eq 'date' ?
local_date(scalar $self->_get('_date_val'), $format) :
$self->_get('_'.$sql_type.'_val');
}


David

--
David Wheeler AIM: dwTheory
david@wheeler.net ICQ: 15726394
http://david.wheeler.net/ Yahoo!: dew7e
Jabber: Theory@jabber.org



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Bricolage-General mailing list
Bricolage-General@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bricolage-general
RE: [Bricolage-General] date formatting [ In reply to ]
Nope. get_data() did look like that, and I changed it to the second, and
still nothing.

Phil

-----Original Message-----
From: David Wheeler [mailto:david@wheeler.net]
Sent: Tuesday, September 24, 2002 11:16 AM
To: Philip Fibiger
Cc: bricolage-general@lists.sourceforge.net
Subject: Re: [Bricolage-General] date formatting

Does the get_data() method look like this for you?:

sub get_data {
my ($self, $format) = @_;
my $sql_type = $self->_get_sql_type or return;
return $sql_type eq 'date' ?
local_date($self->_get('_date_val'), $format) :
$self->_get('_'.$sql_type.'_val');
}

If so, try this instead:

sub get_data {
my ($self, $format) = @_;
my $sql_type = $self->_get_sql_type or return;
return $sql_type eq 'date' ?
local_date(scalar $self->_get('_date_val'), $format) :
$self->_get('_'.$sql_type.'_val');
}


David

--
David Wheeler AIM: dwTheory
david@wheeler.net ICQ: 15726394
http://david.wheeler.net/ Yahoo!: dew7e
Jabber: Theory@jabber.org


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Bricolage-General mailing list
Bricolage-General@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bricolage-general
RE: [Bricolage-General] date formatting [ In reply to ]
On Tue, 24 Sep 2002, Philip Fibiger wrote:

> if (my $pubdate = $element->get_data('publication_date', "%B %Y")) {

That should be:

if (my $pubdate = $element->get_data('publication_date', '%B %Y')) {

With double-quotes %B and %Y are interpolated at hashes. With 'use
strict' in effect this would have given you an error about not declaring
%B and %Y.

-sam



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Bricolage-General mailing list
Bricolage-General@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bricolage-general
Re: [Bricolage-General] date formatting [ In reply to ]
On Tue, 24 Sep 2002, David Wheeler wrote:

> Not true. This script generates no warnings:

Wow, you're right. All this time I thought hashes would interpolate.
Amazing.

-sam




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Bricolage-General mailing list
Bricolage-General@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bricolage-general
Re: [Bricolage-General] date formatting [ In reply to ]
On Tuesday, September 24, 2002, at 12:06 PM, Sam Tregar wrote:

> With double-quotes %B and %Y are interpolated at hashes. With 'use
> strict' in effect this would have given you an error about not
> declaring
> %B and %Y.

Not true. This script generates no warnings:

#! /usr/bin/perl -w
use strict;
use Bric::Util::Time qw(local_date);
print local_date(undef, "%Y %B", 1), "\n";

David

--
David Wheeler AIM: dwTheory
david@wheeler.net ICQ: 15726394
http://david.wheeler.net/ Yahoo!: dew7e
Jabber: Theory@jabber.org



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Bricolage-General mailing list
Bricolage-General@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bricolage-general
Re: [Bricolage-General] date formatting [ In reply to ]
On Tuesday, September 24, 2002, at 12:25 PM, Sam Tregar wrote:

> Wow, you're right. All this time I thought hashes would interpolate.
> Amazing.

Hashes don't interpolate in strings. Never did. :-)

David

--
David Wheeler AIM: dwTheory
david@wheeler.net ICQ: 15726394
http://david.wheeler.net/ Yahoo!: dew7e
Jabber: Theory@jabber.org



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Bricolage-General mailing list
Bricolage-General@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bricolage-general
Re: [Bricolage-General] date formatting [ In reply to ]
On Tuesday, September 24, 2002, at 11:41 AM, Philip Fibiger wrote:

> Nope. get_data() did look like that, and I changed it to the second,
> and
> still nothing.

Okay, trying to replicate...

* I've set up a clean install of 1.4.1 from CVS.
* I added a date field, "big date" to the "Story" element.
* I added this line to the default /story.mc template:

<h2>Date: <% $element->get_data('big_date', "%B %Y") %></h2>

* I deploy the changed /story.mc template.
* I created a story based on the "Story" element and set a date in the
"Big Date" field, then saved it.
* I preview the story...and the date it empty!
* I change the line in /story.mc to this:

<h2>Date: <% $element->get_data('big_date') %></h2>

* I deploy the changed template.
* I preview my test story...and the date shows up!

Okay, so I've replicated the bug. Let me see if I can fix it....

Oh, duh, we're both looking in the wrong place! The $element object is
a container element, not a data element. So if we look at
Bric::Biz::Asset::Business::Parts::Tile::Container->get_data, you'll
see the problem! The second argument is the order number, not the date
format:

=item $string = $tile->get_data($name, $obj_order)

=item $string = $tile->get_data($name, $obj_order, $date_format)

So you need to pass in the date format as the third argument. Returning
to my testing...

* I change the template to look like this:

<h2>Date: <% $element->get_data('big_date', 1, "%B %Y") %></h2>

Note that the "1" can also be "undef" -- the method will change it to
"1".

* I deploy the changed /story.mc template.
* I preview my test story...and it works!

That's what you have to do-- the date format is the third parameter to
the get_data() method, not the second.

HTH,

David

--
David Wheeler AIM: dwTheory
david@wheeler.net ICQ: 15726394
http://david.wheeler.net/ Yahoo!: dew7e
Jabber: Theory@jabber.org



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Bricolage-General mailing list
Bricolage-General@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bricolage-general
RE: [Bricolage-General] date formatting [ In reply to ]
excellent! Works exactly the way I'd expect. Thanks so much for the help..

Phil

-----Original Message-----
From: David Wheeler [mailto:david@wheeler.net]
Sent: Tuesday, September 24, 2002 4:23 PM
To: Philip Fibiger
Cc: bricolage-general@lists.sourceforge.net
Subject: Re: [Bricolage-General] date formatting

* I preview my test story...and it works!

That's what you have to do-- the date format is the third parameter to
the get_data() method, not the second.



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Bricolage-General mailing list
Bricolage-General@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bricolage-general