Added DateIso, DateTimeIso, DateTimeRfc2822 and TimeIso

This commit is contained in:
Erik C. Thauvin 2023-03-15 02:08:27 -07:00
parent 5bd48a4031
commit b92b01a6cc
5 changed files with 226 additions and 0 deletions

View file

@ -7,6 +7,12 @@ This project provides a set of template renderers.
- **rife.render.Capitalize**
- Capitalizes a template value.
- **rife.render.DateIso**
- Renders the current date in ISO 8061 format.
- **rife.render.DateTimeIso**
- Renders the current date and time in ISO 8061 format.
- **rife.render.DateTimeRfc2822**
- Renders the current date and time in RFC 2822 format.
- **rife.render.EncodeBase64**
- Encodes a template value to Base64.
- **rife.render.EncodeHtml**
@ -29,6 +35,8 @@ This project provides a set of template renderers.
- Translates a template value to/from ROT13.
- **rife.render.SwapCase**
- Swap case of a template value.
- **rife.render.TimeIso**
- Renders the current time in ISO 8061 format.
- **rife.render.Trim**
- Removes leading and trailing whitespace from a template value.
- **rife.render.Uncapitalize**

View file

@ -0,0 +1,56 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package rife.render;
import rife.template.Template;
import rife.template.ValueRenderer;
import rife.tools.Localization;
import java.text.DateFormat;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
/**
* <p>Return the current date in ISO 8601 format.</p>
*
* <p>Usage:</p>
*
* <pre>
* &lt;!--v render:rife.render.DateIso/--&gt;
* {{v render:rife.render.DateIso}}
* </pre>
*
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 1.0
*/
public class DateIso implements ValueRenderer {
/**
* ISO 8601 date and time formatter.
*/
static public final DateTimeFormatter iso8601Formatter =
DateTimeFormatter.ofPattern("yyyy-MM-dd").withLocale(Localization.getLocale());
/**
* {@inheritDoc}
*/
@Override
public String render(Template template, String valueId, String differentiator) {
return ZonedDateTime.now().format(iso8601Formatter);
}
}

View file

@ -0,0 +1,54 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package rife.render;
import rife.template.Template;
import rife.template.ValueRenderer;
import rife.tools.Localization;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
/**
* <p>Return the current date and time in ISO 8601 format.</p>
*
* <p>Usage:</p>
*
* <pre>
* &lt;!--v render:rife.render.DateTimeIso/--&gt;
* {{v render:rife.render.DateTimeIso}}
* </pre>
*
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 1.0
*/
public class DateTimeIso implements ValueRenderer {
/**
* ISO 8601 date and time formatter.
*/
static public final DateTimeFormatter iso8601Formatter =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXXXX").withLocale(Localization.getLocale());
/**
* {@inheritDoc}
*/
@Override
public String render(Template template, String valueId, String differentiator) {
return ZonedDateTime.now().format(iso8601Formatter);
}
}

View file

@ -0,0 +1,54 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package rife.render;
import rife.template.Template;
import rife.template.ValueRenderer;
import rife.tools.Localization;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
/**
* <p>Return the current date and time in RFC 2822 format.</p>
*
* <p>Usage:</p>
*
* <pre>
* &lt;!--v render:rife.render.DateTimeRfc2822/--&gt;
* {{v render:rife.render.DateTimeRfc2822}}
* </pre>
*
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 1.0
*/
public class DateTimeRfc2822 implements ValueRenderer {
/**
* RFC 2822 date and time formatter.
*/
static public final DateTimeFormatter rfc2822Formatter =
DateTimeFormatter.ofPattern("EEE, d MMM yyyy HH:mm:ss zzz").withLocale(Localization.getLocale());
/**
* {@inheritDoc}
*/
@Override
public String render(Template template, String valueId, String differentiator) {
return ZonedDateTime.now().format(rfc2822Formatter);
}
}

View file

@ -0,0 +1,54 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package rife.render;
import rife.template.Template;
import rife.template.ValueRenderer;
import rife.tools.Localization;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
/**
* <p>Return the current time in ISO 8601 format.</p>
*
* <p>Usage:</p>
*
* <pre>
* &lt;!--v render:rife.render.TimeIso/--&gt;
* {{v render:rife.render.TimeIso}}
* </pre>
*
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 1.0
*/
public class TimeIso implements ValueRenderer {
/**
* ISO 8601 time formatter.
*/
static public final DateTimeFormatter iso8601Formatter =
DateTimeFormatter.ofPattern("HH:mm:ss").withLocale(Localization.getLocale());
/**
* {@inheritDoc}
*/
@Override
public String render(Template template, String valueId, String differentiator) {
return ZonedDateTime.now().format(iso8601Formatter);
}
}