Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bleargh45/template-plugin-timedate
Template::Toolkit plugin to parse/format dates using TimeDate
https://github.com/bleargh45/template-plugin-timedate
template-toolkit
Last synced: about 1 month ago
JSON representation
Template::Toolkit plugin to parse/format dates using TimeDate
- Host: GitHub
- URL: https://github.com/bleargh45/template-plugin-timedate
- Owner: bleargh45
- Created: 2021-01-10T03:42:51.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-06-12T20:11:26.000Z (over 1 year ago)
- Last Synced: 2024-10-15T16:24:10.375Z (3 months ago)
- Topics: template-toolkit
- Language: Perl
- Homepage: http://metacpan.org/release/Template-Plugin-TimeDate/
- Size: 39.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changes
Awesome Lists containing this project
README
# NAME
Template::Plugin::TimeDate - Template::Toolkit plugin to parse/format dates using TimeDate
# SYNOPSIS
```perl
[% USE TimeDate %]# get current time, as "seconds since the epoch"
[% TimeDate.now %]# parse date string and show in default format (ISO8601)
[% TimeDate.parse('2007-09-02 12:34:56 PDT') %]# parse date string with explicit time zone
[% TimeDate.parse('2007-09-02 12:34:56', 'EDT') %]# get current time, with custom format
[% TimeDate.format('%b %e %Y @ %l:%M %p') %]# parse/display
[% USE mydate = TimeDate('2007-09-02 12:34:56 PDT') %]
[% mydate.format('%b %e %Y @ %l:%M %p') %]# method chaining
[% USE mydate = TimeDate %]
[% mydate.parse('2007-09-02 12:34:56 PDT').format('%Y-%m-%d %H:%M:%S %z') %]
```# DESCRIPTION
`Template::Plugin::TimeDate` is a `Template::Toolkit` plug-in that makes of
the `Date::Parse` and `Date::Format` modules from the `TimeDate`
distribution, to help deal with parsing/formatting dates.Why another date/time plug-in? `Template::Plugin::Date` doesn't handle output
in different timezones, and `Template::Plugin::DateTime` didn't give me a means
of easily parsing dates before turning them into `DateTime` objects. I'd been
using the `Date::Parse` module elsewhere to parse dates, and so this plug-in
was built to help capture the parse/format cycle that I wanted to use in my
templates.The plug-in should be loaded via the USE directive:
```
[% USE TimeDate %]
```This creates a plug-in object with the default name of 'TimeDate'. An
alternate name can be specified such as:```perl
[% USE mydate = TimeDate %]
```# METHODS
- new(string)
Creates a new TimeDate plug-in object, returning it to the caller. An
optional date/time string may be passed in, which is parsed automatically.- now
Sets the current time to "now", and returns it as "the number of seconds
since the epoch".- epoch
Returns the currently set time as "the number of seconds since the epoch".
If a date/time hasn't explicitly been parsed, we default to the current
time.- parse(string, zone)
Parses the given date/time `string` and sets that as the current time
value for further operations. An optional time `zone` is used if there is
no time zone information present in the provided date string.- str2time(string, zone)
An alternate name for the `parse` method above.
- format(format, zone)
Formats the current time value using the given strftime `format`,
optionally converting it into the given time `zone`. If a date/time hasn't
explicitly been parsed, we default to the current time.You may also refer to this method as `time2str`; its original name from
the `Date::Format` module.- time2str(format, zone)
An alternate name for the `format` method above.
- stringify
Stringifies the object, in ISO8601 format (%Y-%m-%d %H:%M:%S).
This method is overloaded, so that simply turning the TimeDate object into
a string will output it in ISO8601 format.# AUTHOR
Graham TerMarsch ([email protected])
# COPYRIGHT
Copyright (C) 2007, Graham TerMarsch. All Rights Reserved.
This is free software; you can redistribute it and/or modify it under the same
terms as Perl itself.# SEE ALSO
[Date::Parse](https://metacpan.org/pod/Date%3A%3AParse),
[Date::Format](https://metacpan.org/pod/Date%3A%3AFormat),
[Template](https://metacpan.org/pod/Template).