EZproxy Date Formatting
From WCN
For consistency sake we need to standardize the date format that is passed back in the User Object for "expiry date" and "join date". Once we verify that all OCLC applications can accept other date formats this restriction will be removed.
The date conversion code used will depend on the date format your authentication source returns. A line code needs to be inserted in to user.txt file for any date that can be harvested. The dates that are currently accepted are "expiry date" and "join date"
No further code is required if one of the following is true:
- Your authentication source returns the date in the MM-DD-YYYY format.
- Your authentication source does not return "expiry date" or "join date".
The following directive must be present in the user.txt when harvesting dates:
- Set session:dateFormat = "MM-DD-YYYY"
Contents |
[edit] Session Variables
Each authentication method returns a different parameter name for the session variable. For example the III authentication will return [p43] for the expiry date and [p83] for the join date.
In this example the III parameter for join date is put in a user object session variable called "joinDate".
# created date set to joinDate Set session:joinDate = auth:p83
[edit] Instructions to insert date formatting code
These modifications will need to be made in the user.txt file.
- Find the session variables for "expiry date" and/or "join date" returned from the authentication source.
- Find the date format returned from the authentication source and use the code below for that format.
- Add the conversion code that matches the date format
- Replace the <session param for join | expiry date> with the correct join and/or expiry date variable for your authentication source.
- Replace the <joinDate | expiryDate> with the correct join and/or expiry date variable for your authentication source.
- Verify that the following directive is found in user.txt Set session:dateFormat = "MM-DD-YYYY"
- Save the user.txt file
It is important to note that the EZproxy DateTime function expects arguments in a specific order. Always list in the following order: YEAR, MONTH, DAY.
[edit] Convert joinDate (III) MM-DD-YY and MM/DD/YY --> MM-DD-YYYY
Set session:dateFormat = "MM-DD-YYYY # Convert date format from "MM-DD-YY" and "MM/DD/YY"
if p83 =~ "@^(\\d\\d?)[-/](\\d\\d?)[-/](\\d\\d?)$@" { Set session:joinDate = FormatDateTime("%m-%d-%Y", DateTime(re:3,re:1,re:2)) }
[edit] Convert expiryDate (III) MM-DD-YY and MM/DD/YY --> MM-DD-YYYY
Set session:dateFormat = "MM-DD-YYYY # Convert date format from "MM-DD-YY" and "MM/DD/YY"
if p43 =~ "@^(\\d\\d?)[-/](\\d\\d?)[-/](\\d\\d?)$@" { Set session:expiryDate = FormatDateTime("%m-%d-%Y", DateTime(re:3,re:1,re:2)) }
[edit] Convert MM/DD/YYYY --> MM-DD-YYYY
Set session:dateFormat = "MM-DD-YYYY # Convert date format from "MM/DD/YYYY"
if <session param for join | expiry date> =~ "@^(\\d\\d?)/(\\d\\d?)/(\\d\\d\\d\\d?)$@" { Set session:<joinDate | expiryDate> = FormatDateTime("%m-%d-%Y", DateTime(re:3,re:1,re:2)) }
