« blib/lib/WWW/Shopify/Liquid/Dialect/Web/Filter/LinkTo.pm
↑ Summary
blib/lib/WWW/Shopify/Liquid/Filter/MD5.pm »
| 1 | #!/usr/bin/perl | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | package WWW::Shopify::Liquid::Filter::DateMath; | ||
| 6 | use base 'WWW::Shopify::Liquid::Filter'; | ||
| 7 | # +-, #, <unit> | ||
| 8 | sub min_arguments { return 2; } | ||
| 9 | sub max_arguments { return 2; } | ||
| 10 | sub operate { | ||
| 11 | my ($self, $hash, $operand, @arguments) = @_; | ||
| 12 | my ($number, $unit) = @arguments; | ||
| 13 | $unit = lc($unit); | ||
| 14 | return undef unless ref($operand) && ref($operand) eq "DateTime"; | ||
| 15 | return $operand unless $unit =~ m/^(days|months|years|weeks|seconds|minutes|hours)$/; | ||
| 16 | return $operand->clone->add( | ||
| 17 | $unit => $number | ||
| 18 | ); | ||
| 19 | } | ||
| 20 | |||
| 21 | 1; |