The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mojar::Cron::Util - Time utility functions

SYNOPSIS

  use Mojar::Cron::Util 'date_next';

DESCRIPTION

Utility functions for dates and times.

FUNCTIONS

time_to_zero

  ($S, $M, $H, $d, $m, $y) = time_to_zero($S, $M, $H, $d, $m, $y);

Converts time representations to zero-based datetimes. So day 1 translates to 0, while months and years are left 0-based.

zero_to_time

  ($S, $M, $H, $d, $m, $y) = zero_to_time($S, $M, $H, $d, $m, $y);

Converts zero-based datetimes to time representations. So day 0 translates to 1, but months and years are left 0-based.

cron_to_zero

  ($S, $M, $H, $d, $m, $y) = cron_to_zero($S, $M, $H, $d, $m, $y);

Converts cron representations to zero-based datetimes. So day 1 translates to 0, month 1 translates to 0 (January), while years are left 0-based.

zero_to_cron

  ($S, $M, $H, $d, $m, $y) = zero_to_cron($S, $M, $H, $d, $m, $y);

Converts zero-based datetimes to cron representations. So day 0 translates to 1, month 0 translates to 1 (January), but years are left 0-based.

life_to_zero

  ($S, $M, $H, $d, $m, $y) = life_to_zero($S, $M, $H, $d, $m, $y);

Converts real-life representations to zero-based datetimes. So day 1 translates to 0, month 1 translates to 0 (January), and year 1900 translates to 0.

zero_to_life

  ($S, $M, $H, $d, $m, $y) = zero_to_life($S, $M, $H, $d, $m, $y);

Converts zero-based datetimes to real-life representations. So day 0 translates to 1, month 0 translates to 1 (January), and year 0 translates to 1900.

balance

  ($S, $M, $H, $d, $m, $y) = balance($S, $M, $H, $d, $m, $y);

Balance-out any simple-minded anomalies such as seconds being less than 0 or greater than 59, or days being less than 0 or greater than 31. This lets you make crude adjustments, such as adding 30 mins, and then letting this function balance it back into the realms of normality. Note that it takes care of everything except the length of months, and so is mainly only used by the two normalise functions which will handle that.

normalise_utc

  ($S, $M, $H, $d, $m, $y) = normalise_utc($S, $M, $H, $d, $m, $y);

Normalises a UTC datetime to a valid value. For example, 31 April translates to 1 May.

normalise_local

  ($S, $M, $H, $d, $m, $y) = normalise_local($S, $M, $H, $d, $m, $y);

Normalises a local datetime to a valid value. For example, 31 April translates to 1 May.

date_today

  $today = date_today();  # yyyy-mm-dd

Provides today's date, using the local (system) clock.

date_previous

  $previous = date_previous('2015-03-01');
  $yesterday = date_previous(date_today());

Provides the previous date.

date_next

  $next = date_next('2015-02-28');
  $tomorrow = date_next(date_today());

Provides the following date.

utc_to_ts

local_to_ts

ts_to_utc

ts_to_local

local_to_utc

utc_to_local

str_to_delta

tz_offset

  $offset = tz_offset;
  $offset = tz_offset($epoch);

Provides the numeric timezone offset, taking daylight saving into account. It is more portable than

  POSIX::strftime('%z')

as it works on non-nix platforms such as Windows. This is required by some date formats, such as in SMTP.

COPYRIGHT AND LICENCE

Copyright (C) 2012--2016, Nic Sandfield.

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.

SEE ALSO

Mojar::Util, POSIX.