Skip to content

Zaneham/rpg-dateutil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rpg-dateutil

Date utility service program for ILE RPG IV. 33 procedures covering business days, ISO weeks, day-count conventions, quarter arithmetic, NZ public holidays, Easter, age calculation, and date formatting.

A collection of date procedures that every RPG shop writes from scratch at least once, usually badly, always at 4pm on the day before go-live. This aims to be the last time.

Distributed via MPB (Mainframe Package Bureau). Full parity with cobol-dateutil plus 19 additional procedures.

Install

mpb install rpg-dateutil

Or copy DTUTIL.RPGLE and DTUTIL_H.RPGLE to your IFS.

Build

CRTRPGMOD MODULE(MYLIB/DTUTIL) SRCSTMF('/path/to/DTUTIL.RPGLE')
CRTSRVPGM SRVPGM(MYLIB/DTUTIL) EXPORT(*ALL)

Bind to your program:

CRTPGM PGM(MYLIB/MYPGM) MODULE(MYLIB/MYPGM) BNDSRVPGM(MYLIB/DTUTIL)

Usage

**FREE
CTL-OPT DFTACTGRP(*NO) BNDDIR('DTUTIL');

/INCLUDE DTUTIL_H

DCL-S today  DATE INZ(*SYS);
DCL-S bdays  INT(10);
DCL-S eom    DATE;
DCL-S isHol  IND;
DCL-S frac   PACKED(15 : 10);

// Business days between two dates
bdays = dt_bdays(D'2026-01-01' : today);

// End of month
eom = dt_eom(today);

// Is it a NZ public holiday?
isHol = dt_nzhol(today);

// ACT/360 day count fraction for a bond
frac = dt_a360(D'2026-01-15' : D'2026-07-15');

// Add 5 business days (skips weekends)
DCL-S settle DATE;
settle = dt_addbd(today : 5);

// Easter Sunday
DCL-S easter DATE;
easter = dt_easter(2026);  // 2026-04-05

Procedures

Calendar Queries

Procedure Description
dt_isleap(year) Is year a leap year?
dt_dim(year : month) Days in month (1-12)
dt_doy(date) Day of year (1-366)
dt_dow(date) Day of week (1=Mon .. 7=Sun, ISO 8601)
dt_valid(y : m : d) Validate date components

ISO Week

Procedure Description
dt_isoweek(date) ISO 8601 week number (1-53)
dt_isowkyr(date) ISO week-year (may differ from calendar year)

Quarter Arithmetic

Procedure Description
dt_qtr(date) Quarter number (1-4)
dt_qtrst(date) First day of quarter
dt_qtred(date) Last day of quarter

Month Boundaries

Procedure Description
dt_eom(date) Last day of month
dt_bom(date) First day of month
dt_iseom(date) Is end of month?

Weekday / Weekend

Procedure Description
dt_iswkd(date) Is weekday? (Mon-Fri)
dt_iswke(date) Is weekend? (Sat-Sun)
dt_nxwkd(date) Next weekday on or after
dt_pvwkd(date) Previous weekday on or before

Date Arithmetic

Procedure Description
dt_dbtwn(d1 : d2) Signed days between (d2 - d1)
dt_adddy(date : n) Add N calendar days

Business Days

Procedure Description
dt_bdays(d1 : d2) Weekday count between dates
dt_addbd(date : n) Add N business days (skips weekends)
dt_nzbdy(d1 : d2) NZ business days (excl. public holidays)

Holidays

Procedure Description
dt_easter(year) Easter Sunday (Gregorian, 1583-9999)
dt_gfri(year) Good Friday
dt_emon(year) Easter Monday
dt_mtk(year) Matariki date (2022-2052, legislated)
dt_nzhol(date) Is NZ public holiday?

Day-Count Conventions (Finance)

Procedure Description
dt_aa(d1 : d2) ACT/ACT (ISDA)
dt_a360(d1 : d2) ACT/360
dt_a365(d1 : d2) ACT/365
dt_30360(d1 : d2) 30/360 (US/NASD)
dt_30e(d1 : d2) 30E/360 (European)
dt_30365(d1 : d2) 30/365 (Nordic)

Other

Procedure Description
dt_age(birth : asOf) Age in whole years
dt_fmtiso(date) Format as YYYY-MM-DD
dt_fmtusa(date) Format as MM/DD/YYYY
dt_fmteur(date) Format as DD.MM.YYYY

NZ Public Holidays

Implements all public holidays per the Holidays Act 2003 with mondayisation:

  • New Year's Day + Day After New Year's
  • Waitangi Day (6 Feb)
  • ANZAC Day (25 Apr)
  • Good Friday + Easter Monday
  • Matariki (legislated dates, 2022-2052)
  • King's Birthday (1st Monday of June)
  • Labour Day (4th Monday of October)
  • Christmas Day + Boxing Day

Matariki dates are from Schedule 1 of the Te Kāhui o Matariki Public Holiday Act 2022, verified against legislation.govt.nz. All 31 dates confirmed as Fridays.

Regional anniversary days are not included.

Testing

TDTUTIL.RPGLE is a test program with 60+ assertions covering all procedures. Compile and run on IBM i:

CRTBNDRPG PGM(MYLIB/TDTUTIL) SRCSTMF('/path/to/TDTUTIL.RPGLE')
CALL TDTUTIL

test_dtutil.c is a C cross-validation harness (54 tests) that verifies the same algorithms on any platform:

gcc -o test_dtutil test_dtutil.c -Wall
./test_dtutil

Requirements

  • ILE RPG IV, V7R3 or later (fully free-form)
  • No external dependencies

License

Apache 2.0

About

Date utility service program for ILE RPG IV — business days, ISO weeks, day-count conventions, NZ holidays, Easter. Distributed via MPB.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors