Create tag for displaying language-specific date parts

2 views
Skip to first unread message

Alexander Obuhovich

unread,
Nov 30, 2009, 7:57:39 AM11/30/09
to In-Portal Development
I propose to create tag for displaying language-specific date parts, like weekday, month name etc. on site language, not always on english as date function of php offers.

--
Best Regards,

http://www.in-portal.org
http://www.alex-time.com

Dmitry

unread,
Nov 30, 2009, 11:09:23 AM11/30/09
to in-por...@googlegroups.com
Actually I have came across this before and did some customization, here is my code for the Languages_tp.php


                /**
* Returns formatted date + time on current language
*
* @param Array $params
* @return string
*/
function CurrentDate($params)
{
$format = $params['format'];
$date = adodb_mktime() + $this->Application->TimeZoneAdjustment();

// special processing for week days and months
if ( (strpos($format, 'l') !== false) || (strpos($format, 'F') !== false) ) {

if ( (strpos($format, 'l') !== false) ) {
$week_day = $this->Application->Phrase('lu_weekday_'.adodb_date('l', $date));
$format = str_replace('l', '#@#', $format); // replace with reserved char (preserves translation link)
}

if ( (strpos($format, 'F') !== false) ) {
$month = $this->Application->Phrase('lu_month_'.adodb_date('F', $date));
$format = str_replace('F', '#@@#', $format); // replace with reserved char (preserves translation link)
}

return str_replace( '#@#', $week_day, str_replace('#@@#', $month, adodb_date($format, $date)) );
}

return adodb_date($format, $date);
}


What if we add parameter to this tag to allow more flexibility so it looks like this:

<inp2:language_CurrentDate use_phrases="1" />

Only then the above phrase conversions will be used?




-- 


--
Best Regards,

Dmitry V. Andrejev
--

You received this message because you are subscribed to the Google Groups "In-Portal Development" group.
To post to this group, send email to in-por...@googlegroups.com.
To unsubscribe from this group, send email to in-portal-de...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/in-portal-dev?hl=en.

Alexander Obuhovich

unread,
Nov 30, 2009, 3:54:55 PM11/30/09
to in-por...@googlegroups.com
Here is another version:


/**
         * Returns formatted date + time on current language
         *
         * @param string $format
         * @param int $timestamp
         * @param string $case_suffixes
         * @return string
         */
        function LanguageDate($format, $timestamp = false, $case_suffixes = '')
        {
            if (!$timestamp) $timestamp = adodb_mktime();
            // apply timezone adjustment manually (because we are not using kDateFormatter)
            $date = $timestamp + $this->Application->TimeZoneAdjustment();

            $replacements = Array (
                'l' => 'la_WeekDay',
                'D' => 'la_WeekDay',
                'M' => 'la_Month',
                'F' => 'la_Month',
            );

            if ($case_suffixes) {
                // apply case suffixes (for russian language only)
                $case_suffixes = explode(',', $case_suffixes);

                foreach ($case_suffixes as $case_suffux) {
                    list ($replacement_name, $case_suffix_value) = explode('=', $case_suffux, 2);
                    $replacements[$replacement_name] .= $case_suffix_value;
                }
            }

            foreach ($replacements as $format_char => $phrase_prefix) {
                if (strpos($format, $format_char) === false) {
                    unset($replacements[$format_char]);
                    continue;
                }

                $replacements[$format_char] = $this->Application->Phrase($phrase_prefix . adodb_date($format_char, $date));
                $format = str_replace($format_char, '#' . ord($format_char) . '#', $format);
            }

            $date_formatted = adodb_date($format, $date);

            foreach ($replacements as $format_char => $format_replacement) {
                $date_formatted = str_replace('#' . ord($format_char) . '#', $format_replacement, $date_formatted);
            }

            return $date_formatted;
        }

But it should be converted to tag, because now it's helper method.

Dmitry A.

unread,
Dec 6, 2009, 11:48:54 PM12/6/09
to In-Portal Development
Hi Alex,


Would please clarify on this:

"But it should be converted to tag, because now it's helper method."

I suppose your code is a new task for Language Tag Processor?


DA.
> > *From*: Alexander Obuhovich <aik.b...@gmail.com<Alexander%20Obuhovich%20%3caik.b...@gmail.com%3e>
>
> > *Reply-To*: in-por...@googlegroups.com
> > *To*: In-Portal Development <in-por...@googlegroups.com<In-Portal%20Development%20%3cin-portal-dev@ googlegroups.com%3e>
>
> > *Subject*: Create tag for displaying language-specific date parts
> > *Date*: Mon, 30 Nov 2009 14:57:39 +0200
>
> > I propose to create tag for displaying language-specific date parts, like
> > weekday, month name etc. on site language, not always on english as date
> > function of php offers.
>
> > --
> > Best Regards,
>
> >http://www.in-portal.org
> >http://www.alex-time.com
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "In-Portal Development" group.
> > To post to this group, send email to in-por...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > in-portal-de...@googlegroups.com<in-portal-dev%2Bunsubscribe@goog legroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/in-portal-dev?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "In-Portal Development" group.
> > To post to this group, send email to in-por...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > in-portal-de...@googlegroups.com<in-portal-dev%2Bunsubscribe@goog legroups.com>
> > .

Alexander Obuhovich

unread,
Dec 7, 2009, 2:49:19 AM12/7/09
to in-por...@googlegroups.com
Not task, but tag. No, my code is supposed to be new tag in kDBTagProcessor like Field tag is. Only difference is that it will display formatted date field contents. Optional parameter "value" will allow to format any abstract date as well (not from database). Code, I've attached is helper method, that was called from LanguageDate tag.

Tag CurrentDate in LanguageTagProcessor is not related to this discussion in any way.

To unsubscribe from this group, send email to in-portal-de...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/in-portal-dev?hl=en.


Dmitry Andrejev

unread,
Dec 7, 2009, 10:59:23 AM12/7/09
to in-por...@googlegroups.com
Sorry - it was a typo. Yes, it's a new tag.

Let's file a task for it.


DA.
>> Alexander%20Obuhovich%20%3caik.b...@gmail.com<Alexander%2520Obuhovich%2520%253caik.b...@gmail.com>
>> %3e>
>> >
>> > > *Reply-To*: in-por...@googlegroups.com
>> > > *To*: In-Portal Development <in-por...@googlegroups.com
>> <In-Portal%20Development%20%3cin-portal-dev@ googlegroups.com%3e>
>> >
>> > > *Subject*: Create tag for displaying language-specific date parts
>> > > *Date*: Mon, 30 Nov 2009 14:57:39 +0200
>> >
>> > > I propose to create tag for displaying language-specific date parts,
>> like
>> > > weekday, month name etc. on site language, not always on english as
>> date
>> > > function of php offers.
>> >
>> > > --
>> > > Best Regards,
>> >
>> > >http://www.in-portal.org
>> > >http://www.alex-time.com
>> >
>> > > --
>> >
>> > > You received this message because you are subscribed to the Google
>> Groups
>> > > "In-Portal Development" group.
>> > > To post to this group, send email to in-por...@googlegroups.com.
>> > > To unsubscribe from this group, send email to
>> > > in-portal-de...@googlegroups.com<in-portal-dev%2Bunsu...@googlegroups.com>
>> <in-portal-dev%2Bunsubscribe@goog legroups.com>
>> > > .
>> > > For more options, visit this group at
>> > >http://groups.google.com/group/in-portal-dev?hl=en.
>> >
>> > > --
>> > > You received this message because you are subscribed to the Google
>> Groups
>> > > "In-Portal Development" group.
>> > > To post to this group, send email to in-por...@googlegroups.com.
>> > > To unsubscribe from this group, send email to
>> > > in-portal-de...@googlegroups.com<in-portal-dev%2Bunsu...@googlegroups.com>
>> <in-portal-dev%2Bunsubscribe@goog legroups.com>
>> > > .
>> > > For more options, visit this group at
>> > >http://groups.google.com/group/in-portal-dev?hl=en.
>> >
>> > --
>> > Best Regards,
>> >
>> > http://www.in-portal.orghttp://www.alex-time.com
>>
>> --
>>
>> You received this message because you are subscribed to the Google Groups
>> "In-Portal Development" group.
>> To post to this group, send email to in-por...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> in-portal-de...@googlegroups.com<in-portal-dev%2Bunsu...@googlegroups.com>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/in-portal-dev?hl=en.
>>
>>
>>
>
>
> --
> Best Regards,
>
> http://www.in-portal.org
> http://www.alex-time.com
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "In-Portal Development" group.
> To post to this group, send email to in-por...@googlegroups.com.
> To unsubscribe from this group, send email to

Alexander Obuhovich

unread,
Dec 7, 2009, 1:18:16 PM12/7/09
to in-por...@googlegroups.com
Ok.

Dmitry A.

unread,
Dec 16, 2009, 2:54:17 PM12/16/09
to In-Portal Development
Ok, time to file a new Feature Request for this.

Finally feature request has been filed for this:


453: Create new Tag to display language-specific Date parts

http://tracker.in-portal.org/view.php?id=453


DA.


On Dec 7, 12:18 pm, Alexander Obuhovich <aik.b...@gmail.com> wrote:
> Ok.
>
>
>
>
>
> On Mon, Dec 7, 2009 at 5:59 PM, Dmitry Andrejev <dandre...@gmail.com> wrote:
> > Sorry - it was a typo. Yes, it's a new tag.
>
> > Let's file a task for it.
>
> > DA.
>
> > On 12/7/09, Alexander Obuhovich <aik.b...@gmail.com> wrote:
> > > Not task, but tag. No, my code is supposed to be new tag in
> > kDBTagProcessor
> > > like Field tag is. Only difference is that it will display formatted date
> > > field contents. Optional parameter "value" will allow to format any
> > abstract
> > > date as well (not from database). Code, I've attached is helper method,
> > that
> > > was called from LanguageDate tag.
>
> > > Tag CurrentDate in LanguageTagProcessor is not related to this discussion
> > in
> > > any way.
>
> > <Alexander%2520Obuhovich%2520%253caik.b...@gmail.com<Alexander%252520Obuhovich%252520%25253caik.b...@gmail.com>
>
> > >> %3e>
>
> > >> > > *Reply-To*: in-por...@googlegroups.com
> > >> > > *To*: In-Portal Development <in-por...@googlegroups.com
> > >> <In-Portal%20Development%20%3cin-portal-dev@ googlegroups.com%3e>
>
> > >> > > *Subject*: Create tag for displaying language-specific date parts
> > >> > > *Date*: Mon, 30 Nov 2009 14:57:39 +0200
>
> > >> > > I propose to create tag for displaying language-specific date parts,
> > >> like
> > >> > > weekday, month name etc. on site language, not always on english as
> > >> date
> > >> > > function of php offers.
>
> > >> > > --
> > >> > > Best Regards,
>
> > >> > >http://www.in-portal.org
> > >> > >http://www.alex-time.com
>
> > >> > > --
>
> > >> > > You received this message because you are subscribed to the Google
> > >> Groups
> > >> > > "In-Portal Development" group.
> > >> > > To post to this group, send email to in-por...@googlegroups.com
> > .
> > >> > > To unsubscribe from this group, send email to
> > >> > > in-portal-de...@googlegroups.com<in-portal-dev%2Bunsubscribe@goog­legroups.com>
> > <in-portal-dev%2Bunsu...@googlegroups.com<in-portal-dev%252Bunsubscribe­@googlegroups.com>
>
> > >> <in-portal-dev%2Bunsubscribe@goog legroups.com>
> > >> > > .
> > >> > > For more options, visit this group at
> > >> > >http://groups.google.com/group/in-portal-dev?hl=en.
>
> > >> > > --
> > >> > > You received this message because you are subscribed to the Google
> > >> Groups
> > >> > > "In-Portal Development" group.
> > >> > > To post to this group, send email to in-por...@googlegroups.com
> > .
> > >> > > To unsubscribe from this group, send email to
> > >> > > in-portal-de...@googlegroups.com<in-portal-dev%2Bunsubscribe@goog­legroups.com>
> > <in-portal-dev%2Bunsu...@googlegroups.com<in-portal-dev%252Bunsubscribe­@googlegroups.com>
>
> > >> <in-portal-dev%2Bunsubscribe@goog legroups.com>
> > >> > > .
> > >> > > For more options, visit this group at
> > >> > >http://groups.google.com/group/in-portal-dev?hl=en.
>
> > >> > --
> > >> > Best Regards,
>
> > >> >http://www.in-portal.orghttp://www.alex-time.com
>
> > >> --
>
> > >> You received this message because you are subscribed to the Google
> > Groups
> > >> "In-Portal Development" group.
> > >> To post to this group, send email to in-por...@googlegroups.com.
> > >> To unsubscribe from this group, send email to
> > >> in-portal-de...@googlegroups.com<in-portal-dev%2Bunsubscribe@goog­legroups.com>
> > <in-portal-dev%2Bunsu...@googlegroups.com<in-portal-dev%252Bunsubscribe­@googlegroups.com>
>
> > >> .
> > >> For more options, visit this group at
> > >>http://groups.google.com/group/in-portal-dev?hl=en.
>
> > > --
> > > Best Regards,
>
> > >http://www.in-portal.org
> > >http://www.alex-time.com
>
> > > --
>
> > > You received this message because you are subscribed to the Google Groups
> > > "In-Portal Development" group.
> > > To post to this group, send email to in-por...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > in-portal-de...@googlegroups.com<in-portal-dev%2Bunsubscribe@goog­legroups.com>
> > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/in-portal-dev?hl=en.
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "In-Portal Development" group.
> > To post to this group, send email to in-por...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > in-portal-de...@googlegroups.com<in-portal-dev%2Bunsubscribe@goog­legroups.com>

Alexander Obuhovich

unread,
Dec 19, 2009, 5:32:55 AM12/19/09
to in-por...@googlegroups.com
Here is the final path for testing. I've also attached it to the task.

To unsubscribe from this group, send email to in-portal-de...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/in-portal-dev?hl=en.


date_field_tag.patch
Reply all
Reply to author
Forward
0 new messages