Date processing

Is Coranto not working properly for you? Here's where to ask for support help; for best results, follow these steps:
  • - Check your core/addon documentation for possible solutions
  • - Search these forums for similar problems that have already been solved
  • - If you're still stumped, check out THIS TOPIC, and post your question in this forum!!

Moderators: Spunkmeyer, Dale Ray, SrNupsen, Bluetooth, Jackanape

Date processing

Postby Flame12121 » Mon May 28, 2007 10:15 pm

Hi,

I've been using coranto/newspro for years now, but I've found myself having a bit of a problem with a new site I'm trying to set up.

This site needs the date format in the form 'YYYY-MM-DDThh:mm:ssZ'

where DD is the day, T is the letter T, and hh is the two-digit hour in 24 hour time, Z is a time zone identifier (in this case Zulu)

Unfortunately, it doesn't seem to want to process that, as when I try this:
"<Field: Year>-<Field: Month >-<Field: Day>T<Field: Hour>" everything from day to hour isn't properly substituted, instead, I get <Field: Day>T<Field: Hour> in the output.

Any suggestsions? I can't change the needed format, unfortunately.

Thanks,

Flame12121
Flame12121
 
Posts: 8
Joined: Tue Feb 20, 2007 5:00 am

Postby Musicvid » Tue May 29, 2007 2:58 am

<Field: Day> and <Field: Hour> aren't defined the way you want them, so you would need to define those variables properly in order to use them in the desired manner on your site. http://www.corantodemo.net/wiki/index.p ... /StyleTags
Code: Select all
use POSIX qw(strftime);
   my @localtime = localtime(time);
   my $NowDate = strftime("%Y-%m-%dT%H:%M:%S%Z" @localtime);
Something like this, perhaps? You could then use the $NowDate variable as <Field: NowDate> inside your style.
I didn't test it, because I have no use for this formatting.
If you want to explore it further, http://search.cpan.org/~gbarr/TimeDate-1.16/lib/Date/Format.pm#CONVERSION_SPECIFICATION
If you are using it inside a Coranto Style, you would need to enclose the code inside <PerlCode></PerlCode> blocks. Hope this helps.
Musicvid
 
Posts: 138
Joined: Wed Jan 17, 2007 1:05 am
Location: Western America

Postby Flame12121 » Tue May 29, 2007 4:03 am

I considered something like that, but I needed to get the UNIX time format for the posts in order to use it. Is that available somewhere?

Also, even if they aren't formatted quite the way I need, shouldn't they still substitute correctly? I'm getting the "<Field: Day>T<Field: Hour>" in the output.

~ Flame12121
Flame12121
 
Posts: 8
Joined: Tue Feb 20, 2007 5:00 am

Postby SrNupsen » Tue May 29, 2007 7:50 am

If I'm not entirely mistaken, then Unix time stamp is available as <Field: newstime>
-----------------------------------------------------------------------------------------------------
Coranto is free software. I am available for custom work or troubleshooting.

http://www.sundaune.no - transkripsjon, webdesign, nettsider, tekstbyrå
http://www.vagbladet.no - satire, politikk, kultur, sport, nettavis
-----------------------------------------------------------------------------------------------------
SrNupsen
 
Posts: 2229
Joined: Tue Jan 09, 2007 6:46 pm
Location: Nesodden, outside Oslo, Norway

Postby Dale Ray » Tue May 29, 2007 2:08 pm

Try looking at Default Style Tags or the Style Guide by Mark Olson.

I think you want to use <Field: TwoDigitMonth> and <Field: TwoDigitDay>

You can also use <Field: Time_Zone> for the time zone if you want to display the same time zone that is defined in the Coranto settings.

What version of Coranto are you using?
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby Flame12121 » Tue May 29, 2007 11:10 pm

I'm using 1.25 off of this website, but the problem existed in 1.24 too.

I just tried "<Field: Year>-<Field: TwoDigitMonth>-<Field: TwoDigitDay>T<Field: Hour>"

And
"<Field: Year>-<Field: TwoDigitMonth>-<Field: TwoDigitDay> T<Field: Hour>"

With the space between the "TwoDigitDay>" and the letter "T" it substitutes correctly, but without the space I get this (directly from View-source in my browser):
"Example of current format: 2007-05-0" (0 being the hour, and the day has vanished)

Looks like an over-greedy regex, but I don't know where it would be.

~ Flame12121
Flame12121
 
Posts: 8
Joined: Tue Feb 20, 2007 5:00 am

Postby Dale Ray » Tue May 29, 2007 11:19 pm

Dale wrote:What version of Coranto are you using?


I asked this because it is pertinent. There was an earlier version of Coranto where the field substitutions did not work correctly without space around them (or with certain characters before or after), anyway - are you using at least V 1.24?
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby Flame12121 » Tue May 29, 2007 11:31 pm

Flame12121 wrote:I'm using 1.25 off of this website, but the problem existed in 1.24 too.


I upgraded a day or so before I posted to see if the problem had been resolved already.

~ Flame12121
Flame12121
 
Posts: 8
Joined: Tue Feb 20, 2007 5:00 am

Found it

Postby Flame12121 » Wed May 30, 2007 11:37 pm

Well, I've identified the source of the problem.

When building dates, a command is created like so:

Code: Select all
qq~$Month $day, $Year~


which works thanks to perl's interpolation.

When your format doesn't put spaces or some other obviously non-variable name in there, you end up with:

Code: Select all
qq~$MonthSomeTextIWantedHere$DaySomeMoreText$Year~


Which will not interpolate correctly because there is no variable "$MonthSomeTextIWantedHere".

The solution:

Replace lines 403-408 of crlib.pl with:
Code: Select all
   $convdateformat =~ s/(\$|\@|\%|\~|\\)/\\$1/g;
   $convdateformat =~ s/<Field\: Abbrev_Weekday>/\$Abbrev_Week_Days[\$Week_Day]/g;
   $convdateformat =~ s/<Field\: Abbrev_Month_Name>/\${Abbrev_Months[\$Month]}/g;
   $convdateformat =~ s/<Field\: Month>/\${Month_Number}/g;
   $convdateformat =~ s/<Field\: UNIXMonth>/\$Month/g;
   $convdateformat =~ s/<Field\: (\w+)>/\${$1}/g;


~ Flame12121
Flame12121
 
Posts: 8
Joined: Tue Feb 20, 2007 5:00 am

Postby Dale Ray » Thu May 31, 2007 10:47 pm

Flame12121,

Thanks for the work tracking this down and reporting a possible fix.
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana


Return to Troubleshooting

Who is online

Users browsing this forum: No registered users and 4 guests

cron