Dotiac

 view release on metacpan or  search on metacpan

lib/Dotiac/DTL/Filter.pm  view on Meta::CPAN

B<This might change if a locale module is loaded.>

=item "n"

Returns the current month as a number without leading zeros.

	{{ var|date: "m" }} {# 1 #} to {# 12 #}

=item "M"

Returns the current in Associated Press style notation.

	{{ var|date: "M" }} {# Jan. #} {# March #} {# July #}

B<This might change if a locale module is loaded.>

=item "O"

Returns the difference to Greenwich time in hours.

	{{ var|date: "O" }} {# +0100 #}

=item "P"

Returns either the time in 12 hours and minutes if not zero with a.m. or p.m., midnight or noon.

	{{ var|date: "P" }} {# 1 p.m. #} {# 11:56 a.m. #} {# midnight #} {# noon #}

=item "r"

Returns an RFC 2822 formatted date.

	{{ var|date: "r" }} {# Sun, 28 Dec 2008 18:36:24 +0200' #}

B<This might change if a locale module is loaded.>

=item "s"

Returns the seconds with a leading zero.

	{{ var|date: "s" }} {# 00 #} to {# 59 #}

=item "S"

Returns the ordinal suffix for the day of the month.

	{{ var|date: "S" }} {# st #} {# nd #} {# rd #} {# th #}

Defaults to english, B<this may change if a locale module is loaded.>

=item "t"

Returns the number of days in the given month.

	{{ var|date: "t" }} {# 28 #} to  {# 31 #}

=item "T"

Returns the current timezone (needs the POSIX module)

	{{ var|date: "T" }} {# CET #} {# GMT #} {# EST #}...

=item "w"

Returns the day of week as a number from 0 (Sunday) to 6 (Saturday)

	{{ var|date: "w" }} {# 1 #} to {# 6 #}

=item "W"

Returns the ISO-8601 week number of year (uses the POSIX module), weeks start on monday.

	{{ var|date: "w" }} {# 1 #} to {# 53 #}

=item "y" 

Returns the year in two digits (with leading zeros) 

	{{ var|date: "y" }} {# 08 #}

=item "Y"

Returns the year in four (or more) digits (with leading zeros) 

	{{ var|date: "Y" }} {# 2008 #}

=item "z"

Returns the day of the year without leading zeros

	{{ var|date: "z" }} {# 0 #} to {# 365 #}

=item "Z"

Returns the difference of the current timezone to GMT in seconds.

	{{ var|date: "Z" }} {# -43200 #} to {# 43200 #}

=back

=head3 Bugs and Differences to Django

Since Perl has no default DateTime Object, this expects a normal unix timestamp ( result of the time() call in perl).

It also excepts the result of localtime as an array reference, this is useful for timestamps > 2038 on 32-Bit machines.

	var=>[36,31,21,2,0,109,5,1,0];
	
	{{ var|date:"jS F Y H:i" }} {# 2nd January 2009 21:31 #}

=head2 default :STRING

If the value is false (See L<Dotiac::DTL::Tag::if>) it will return the STRING, otherwise the value.

	{{ "Hello World"|cut:"el" }} {# Hlo World #}
	{{ "Hello World"|cut:"l" }} {# Heo Word #}

=head3 Bugs and Differences to Django

Perl considers other things false as Python.

lib/Dotiac/DTL/Filter.pm  view on Meta::CPAN

=item "G" 

Returns the hour in 24-hour format without leading zeros.

	{{ var|time: "G" }} {# 0 #} to {# 24 #}

=item "h" 

Returns the hour in 12-hour format with a leading zero.

	{{ var|time: "h" }} {# 01 #} to {# 12 #}

=item "H" 

Returns the hour in 24-hour format with a leading zero.

	{{ var|time: "H" }} {# 00 #} to {# 24 #}

=item "i" 

Returns the minutes with a leading zero.

	{{ var|time: "i" }} {# 00 #} to {# 60 #}

=item "O"

Returns the difference to Greenwich time in hours.

	{{ var|time: "O" }} {# +0100 #}

=item "P"

Returns either the time in 12 hours and minutes if not zero with a.m. or p.m., midnight or noon.

	{{ var|time: "P" }} {# 1 p.m. #} {# 11:56 a.m. #} {# midnight #} {# noon #}

=item "s"

Returns the seconds with a leading zero.

	{{ var|time: "s" }} {# 00 #} to {# 59 #}

=item "Z"

Returns the difference of the current timezone to GMT in seconds.

	{{ var|time: "Z" }} {# -43200 #} to {# 43200 #}

=back

=head3 Bugs and Differences to Django

Since Perl has no default DateTime Object, this expects a normal unix timestamp ( result of the time() call in perl).

It also excepts the result of localtime as an array reference, this is useful for timestamps > 2038 on 32-Bit machines.

	var=>[36,31,21,2,0,109,5,1,0];
	
	{{ var|time:"H:i" }} {# 21:31 #}

=head2 timesince :REFERNCETIME

Formats a time value and displays the time since REFERENCE TIME has passed.

REFERENCETIME is C<now> if it is omitted

If you have a past event and want to display the time since then you can use this filter.

For any time in the future it will return 0 Minutes

	{{ post.date|timesince }} {# 3 years #}
	{{ post.date|timesince:edit.date }} {# 3 minutes #} {# after the post #}

C<timesince> and C<timeuntil> only differ in the order of the arguments:

	{{ date1|timeuntil:date2 }} == {{ date2|timesince:date1 }}

The generated value is always marked as safe.

=head3 Bugs and Differences to Django

Like C<time> and C<date> it only accepts unix timestamps.

If given any additional parameter it will print out the full time, while without it will only print useful information

	{{ post.date|timesice:edit.date;"" }} {# 2 days 3 Minutes #}
	{{ post.date|timesice:"now";"" }} {# 3 years 2 days 2 seconds #} {# compare to current time #}

If you have just a elapsed time in seconds you can use this:

	{{ "0"|timesince:"60" }} {# 1 Minute #}

=head2 timeuntil :REFERNCETIME

Formats a time value and displays the time util REFERENCE TIME.

REFERENCETIME is C<now> if it is omitted.

If you have a funture event and want to display the time util then you can use this filter

For any time in the past it will return 0 Minutes

	{{ marriage.date|timeuntil }} {# 3 years #}
	{{ marriage.date|timeuntil:engagement.date }} {# 3 month #} {# after the engagement #}

C<timesince> and C<timeuntil> only differ in the order of the arguments:

	{{ date1|timesince:date2 }} == {{ date2|timeuntil:date1 }}

The generated value is always marked as safe.

=head3 Bugs and Differences to Django

Like C<time> and C<date> it only accepts unix timestamps.

If given any additional parameter it will print out the full time, while without it will only print useful information

	{{ post.date|timeuntil:edit.date;"" }} {# 3 month 3 Minutes #}
	{{ marriage.date|timeuntil:"now";"" }} {# 3 years 2 days 2 seconds #} {# compare to current time #}

If you have just a elapsed time in seconds you can use this:

	{{ "60"|timeuntil:"0" }} {# 1 Minute #}


=head2 title

Converts the value into titlecase.

	{{ "500 kilos of heroin found"|title }} {# 500 Kilos Of Heroin Found #}

=head3 Bugs and Differences to Django

If you find any, please report them

=head2 truncatewords :NUMBEROFWORDS

Cuts off the value after a specific NUMBER OF WORDS. Replaces the removed parts with "..."

	{{ "500 kilos of heroin found"|truncatewords:"3" }} {# 500 kilos of ... #}
	{{ "Today is monday"|truncatewords:"3" }} {# Today is monday #}

=head3 Bugs and Differences to Django

If you find any, please report them

=head2 truncatewords_html :NUMBEROFWORDS

Cuts off the value after a specific NUMBER OF WORDS. Replaces the removed parts with "..."

Same as C<truncatewords>, but also closes every HTML/XML Tag that's left open after the cutoff.

	{{ "<b>500 kilos <u>of</u> heroin found</b>"|truncatewords:"3" }} {# <b>500 kilos <u>of</u> ...</b> #}
	{{ "Today <u>is</u> monday"|truncatewords:"3" }} {# Today <u>is</u> monday #}

This one is much slower than truncatewords, so use this only when you have HTML tags in your value.



( run in 2.629 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )