BEGIN HEADER CharacterSet "CP1252" ExportingTool "Ascential DataStage Export" ToolVersion "4" ServerName "10.0.0.32" ToolInstanceID "Proj1Dev" MDISVersion "1.0" Date "2005-03-22" Time "10.30.33" ServerVersion "7.5x2" END HEADER BEGIN DSROUTINES BEGIN DSRECORD Identifier "AddDays" DateModified "2005-09-03" TimeModified "10.30.12" OLEType "CRoutine" Readonly "0" Category "Ray Wurlod\\Date" ShortDesc "Add integer number of days to a date" Description =+=+=+= Input arguments: BaseDate - the date, in DataStage internal format, to which a number of days is to be added. DaysOffset - the number of days to be added to BaseDate; must be integer, may be negative. Truncated to integer. Return value: Date in DataStage internal format represented by the arithmetic operation. Returns NULL if BaseDate is not a valid DataStage internal format date. =+=+=+= RoutineType "0" ArgCount "2" Built "1" SourceFlag "1" Vendor "Ray Wurlod ABN 57 092 448 518" Author "Ray Wurlod" Version "2.0.0" Copyright "Copyright (c) 2002-2005 Ray Wurlod. All rights reserved." TestValues "11688\(1B)1\(9)11719\(1B)1\(9)11747\(1B)1\(9)11779\(1B)1\(9)12085\(1B)1\(9)11719\(1B)-1\(9)11747\(1B)-1\(9)11748\(1B)-1\(9)11779\(1B)-1\(9)12113\(1B)-1\(9)12144\(1B)-1\(9)12174\(1B)-1\(9)12054\(1B)0\(9)11688\(1B)12\(9)11748\(1B)12\(9)12144\(1B)-11\(9)12345\(1B)55bc" Source =+=+=+= FUNCTION AddDays(argBaseDate,argDaysOffset) $COPYRIGHT "Copyright (c) 2002-2005 Ray Wurlod. All rights reserved." $* May be freely used with the above copyright notice intact and the code unmodified. Equate RoutineName To "AddDays" * Disable this token if warning messages about first argument are not required to be logged. $DEFINE DATECHECK * Disable this token if warning messages about second argument are not required to be logged. $DEFINE NUMBERCHECK * Calculate integer part of MonthsOffset. DaysOffset = Field(argDaysOffset, ".", 1, 1) $IFDEF NUMBERCHECK If Not(Num(DaysOffset)) Then Call DSTransformError("Number of days offset ( " : Quote(argDaysOffset) : ") is not numeric.", RoutineName) Ans = @NULL GoTo MainExit End $ENDIF * Check that base date is an internal format date. If it is, do day arithmetic. * If not, return NULL. If argBaseDate Matches "1N0N" : @VM : "'-'1N0N" Then Ans = argBaseDate + DaysOffset End Else Ans = @NULL $IFDEF DATECHECK Call DSTransformError("Base date argument is not a valid internal format date.", RoutineName) $ENDIF End MainExit: RETURN(Ans) =+=+=+= Catalog "DSU.AddDays" JobType "0" PlatformType "" Arguments "CRtnArgument" BEGIN DSSUBRECORD Name "argBaseDate" Desc "Date to which argDaysOffset days are to be added" SqlType "0" ColScale "0" IOType "0" NativeType "" Nullable "0" NullValue "" Occurs "0" KeyPosition "0" Precision "0" SignIndicator "" SignOption "0" SyncIndicator "0" Usage "" DateMask "" DependField "" LevelNo "0" RedefinedField "" END DSSUBRECORD BEGIN DSSUBRECORD Name "argDaysOffset" Desc "Number of days to add to BaseDate. May be negative. Must be integer." SqlType "1" ColScale "0" IOType "0" NativeType "" Nullable "0" NullValue "" Occurs "0" KeyPosition "0" Precision "0" SignIndicator "" SignOption "0" SyncIndicator "0" Usage "" DateMask "" DependField "" LevelNo "0" RedefinedField "" END DSSUBRECORD ExternalName "" LibraryPath "" Language "" SkipOnNull "" InvocationMethod "" RoutineJCL "" ReturnType "" END DSRECORD BEGIN DSUBINARY Identifier "DSU.AddDays" B1 "E1DA1175050011000600030000000000100011001B001B000A00110000001400B000000032000000" B41 "130000008400000013BA0000040100000401000001020000CD020000F30200000000000000000000" B81 "08000000840009000B000C000C000100100101000D000E010D000E00DE020E005000000040010900" B121 "1100040103001000110012000200F800130003001E000F00020002000300F8000A000400C2000000" B161 "A0000000260015000E000401030014000E0016001700E000080017001800DE021800000084000000" B201 "0400080001000400C2000000A0000000F8000A000400F80019000500F800130006001E000F000200" B241 "05000600F800040007005C01F8001A0007005C01002E44535472616E73666F726D4572726F724E75" B281 "6D626572206F662064617973206F666673657420282029206973206E6F74206E756D657269632E41" B321 "646444617973314E304E272D27314E304E42617365206461746520617267756D656E74206973206E" B361 "6F7420612076616C696420696E7465726E616C20666F726D617420646174652E062B000000010100" B401 "00000100000003010000000500000000050100000004100000000200000001180000001200000005" B441 "0200000001110000002A00000001070000003B00000001040000004200000003FD00000001070000" B481 "00460000000503000000050400000001370000004D00000001000000008400000000000000000000" B521 "00000000000800000001000100000000001300000002000100000000001A00000003000100000000" B561 "002100000004000100000000002500000005000100000000002C0000000600010000000000330000" B601 "0007000300000000003A0000000800040000000000460000000900040000000000244D4154524958" B641 "00446179734F6666736574005F5430303031005F543030303200416E73005F5430303033005F5430" B681 "303034005F543030303000617267426173654461746500617267446179734F666673657400EFFF00" B721 "00FCFF0C00FEFF140022000600F9FF0800FDFF2400FBFF1000FDFF0600F9FF16000800443A5C4173" B761 "63656E7469616C5C4461746153746167655C50726F6A656374735C50726F6A314465762F4453555F" B801 "42502F4453552E4164644461797300436F707972696768742028632920323030322D323030352052" B841 "6179205775726C6F642E2020416C6C207269676874732072657365727665642E220D00204D617920" B881 "626520667265656C7920757365642077697468207468652061626F766520636F7079726967687420" B921 "6E6F7469636520696E7461637420616E642074686520636F646520756E6D6F6469666965642E0D" END DSUBINARY BEGIN DSRECORD Identifier "AddDaysToTimestamp" DateModified "2005-09-03" TimeModified "10.22.31" OLEType "CRoutine" Readonly "0" Category "Ray Wurlod\\Date" ShortDesc "Add integer number of days to a timestamp" Description =+=+=+= Input arguments: BaseDate - the timestamp, in ISO 8601 format, to which a number of days is to be added. DaysOffset - the number of days to be added to BaseDate; must be integer, may be negative. Truncated to integer. Return value: Timestamp in ISO 8601 format represented by the arithmetic operation. Returns NULL if BaseDate is not a valid timestamp. =+=+=+= RoutineType "0" ArgCount "2" Built "1" SourceFlag "1" Vendor "Ray Wurlod ABN 57 092 448 518" Author "Ray Wurlod" Version "2.0.0" Copyright "Copyright (c) 2002-2005 Ray Wurlod. All rights reserved." TestValues "2005-01-01 12:34:56\(1B)32\(9)2005-01-01 12:34:56\(1B)59\(9)2005-01-01 12:34:56\(1B)-180\(9)2005-01-01 12:34:56\(1B)365\(9)2004-01-01 12:34:56\(1B)365\(9)2004-06-30\(1B)183\(9)2000-01-01 16:40:00.000\(1B)183\(9)2000-01-01 16:40:00.000000\(1B)183\(9)2000-01-01 16:40:00.x\(1B)222\(9)2000-01-01 16:40:00.\(1B)183" Source =+=+=+= FUNCTION AddDaysToTimestamp(argBaseDate,argDaysOffset) $COPYRIGHT "Copyright (c) 2002-2005 Ray Wurlod. All rights reserved." Equate RoutineName To "AddDaysToTimestamp" * Disable this token to disable warnings being logged about first argument. $DEFINE TIMESTAMPCHECK * Disable this token to disable warnings being logged about second argument. $DEFINE NUMBERCHECK * Calculate integer part of DaysOffset. DaysOffset = Field(argDaysOffset, ".", 1, 1) $IFDEF NUMBERCHECK If Not(Num(DaysOffset)) Then Call DSTransformError("Number of days offset ( " : Quote(argDaysOffset) : ") is not numeric.", RoutineName) Ans = @NULL GoTo MainExit End $ENDIF * Check that base date is an internal format date. If it is, do day arithmetic. * If not, return NULL. TimestampPattern = "4N'-'2N'-'2N' '2N':'2N':'2N" Remainder = argBaseDate[21, Len(argBaseDate)] ; * fractional seconds if any If Left(argBaseDate, 19) Matches TimestampPattern And (Remainder Matches "1N0N" Or Remainder = "") Then BaseDate = Iconv(Left(argBaseDate, 10), "DYMD") NewDate = Oconv(BaseDate + DaysOffset, "D-YMD[4,2,2]") NewTimestamp = NewDate : argBaseDate[11,9] : (If Len(Remainder) Then "." : Remainder Else Remainder) Ans = NewTimestamp End Else Ans = @NULL $IFDEF TIMESTAMPCHECK Call DSTransformError(Quote(argBaseDate) : " is not a valid timestamp.", RoutineName) $ENDIF End MainExit: RETURN(Ans) =+=+=+= Catalog "DSU.AddDaysToTimestamp" JobType "0" PlatformType "" Arguments "CRtnArgument" BEGIN DSSUBRECORD Name "argBaseDate" Desc "Date to which DaysOffset months are to be added" SqlType "0" ColScale "0" IOType "0" NativeType "" Nullable "0" NullValue "" Occurs "0" KeyPosition "0" Precision "0" SignIndicator "" SignOption "0" SyncIndicator "0" Usage "" DateMask "" DependField "" LevelNo "0" RedefinedField "" END DSSUBRECORD BEGIN DSSUBRECORD Name "argDaysOffset" Desc "Number of days to add to BaseDate. May be negative. Must be integer. Decimal numbers are truncated to integer." SqlType "1" ColScale "0" IOType "0" NativeType "" Nullable "0" NullValue "" Occurs "0" KeyPosition "0" Precision "0" SignIndicator "" SignOption "0" SyncIndicator "0" Usage "" DateMask "" DependField "" LevelNo "0" RedefinedField "" END DSSUBRECORD ExternalName "" LibraryPath "" Language "" SkipOnNull "" InvocationMethod "" RoutineJCL "" ReturnType "" END DSRECORD BEGIN DSUBINARY Identifier "DSU.AddDaysToTimestamp" B1 "E1DA1175050011000B000300000000001C001D002C002C000F001D00000014003C01000039000000" B41 "1C00000096000000A01B00009001000090010000E3020000240400005C0400000000000000000000" B81 "0800000084000E0010001100110001001001010012000E0112001300DE0213005000000040010E00" B121 "1600040103001500160017000200F800180003001E001400020002000300F8000F000400C2000000" B161 "2C010000F80019000500D0000D001300F0000D001A001300060086020D001B001300E00013000500" B201 "1C00E00006001D001E006E0006001F00200022011E002000210008001C0021002200DE0222000000" B241 "0801000086020D0023002400AC0024002500070004000700010024001201240026000800F0000D00" B281 "270028002400D00006002900DE022900E80000003A00100006002A00C2000000EE000000F8000600" B321 "2A0004010300080024002A000900F80009000400C20000002C010000F8000F00040040010D002400" B361 "3A0024002B000A00F80018000B001E00140002000A000B00F80004000C005C01F8001F000C005C01" B401 "002E44535472616E73666F726D4572726F724E756D626572206F662064617973206F666673657420" B441 "282029206973206E6F74206E756D657269632E41646444617973546F54696D657374616D70344E27" B481 "2D27324E272D27324E272027324E273A27324E273A27324E314E304E44594D44442D594D445B342C" B521 "322C325D206973206E6F7420612076616C69642074696D657374616D702E062B0000000101000000" B561 "01000000030100000005000000000501000000041000000002000000011800000012000000050200" B601 "000001110000002A00000001120000003B000000011B0000004D0000000315000000031300000005" B641 "03000000010400000068000000050400000001000000006C00000005050000000506000000050700" B681 "0000030A000000050800000001040000006C000000010C00000070000000030B0000000309000000" B721 "0509000000050A000000011A0000007C000000000000000000000000000000080000000100010000" B761 "0000001300000002000100000000001A000000030001000000000021000000040001000000000025" B801 "00000005000100000000003600000006000100000000004000000007000100000000004900000008" B841 "000100000000005100000009000100000000005E0000000A00010000000000650000000B00010000" B881 "0000006C0000000C00030000000000730000000D000400000000007F0000000E0004000000000024" B921 "4D415452495800446179734F6666736574005F5430303031005F543030303200416E730054696D65" B961 "7374616D705061747465726E0052656D61696E646572004261736544617465004E65774461746500" B1001 "4E657754696D657374616D70005F5430303033005F5430303034005F543030303000617267426173" B1041 "654461746500617267446179734F666673657400F0FF0000FDFF0C00FEFF140022000600F8FF0800" B1081 "0600FEFF1000FDFF3A00FEFF1000FEFF1000FEFF3A00FBFF0E00FDFF0600FAFF1E000800443A5C41" B1121 "7363656E7469616C5C4461746153746167655C50726F6A656374735C50726F6A314465762F445355" B1161 "5F42502F4453552E41646444617973546F54696D657374616D7000436F7079726967687420286329" B1201 "20323030322D3230303520526179205775726C6F642E2020416C6C20726967687473207265736572" B1241 "7665642E220D00" END DSUBINARY BEGIN DSRECORD Identifier "AddMonths" DateModified "2005-09-03" TimeModified "10.25.56" OLEType "CRoutine" Readonly "0" Category "Ray Wurlod\\Date" ShortDesc "Add integer number of months to a date" Description =+=+=+= Input arguments: BaseDate - the date, in DataStage internal format, to which a number of months is to be added. MonthsOffset - the number of months to be added to BaseDate; must be integer, may be negative. Truncated to integer. Return value: Date in DataStage internal format represented by the arithmetic operation. Returns NULL if BaseDate is not a valid DataStage internal format date. Notes: If the obvious generated date is not legal, the day number of the result is wound back until a valid date is represented. For example, adding 4 months to 31 December will result in 30 April. =+=+=+= RoutineType "0" ArgCount "2" Built "1" SourceFlag "1" Vendor "Ray Wurlod ABN 57 092 448 518" Author "Ray Wurlod" Version "2.0.0" Copyright "Copyright (c) 2002-2005 Ray Wurlod. All rights reserved." TestValues "11688\(1B)1\(9)11719\(1B)1\(9)11747\(1B)1\(9)11779\(1B)1\(9)12085\(1B)1\(9)11719\(1B)-1\(9)11747\(1B)-1\(9)11748\(1B)-1\(9)11779\(1B)-1\(9)12113\(1B)-1\(9)12144\(1B)-1\(9)12174\(1B)-1\(9)12054\(1B)0\(9)11688\(1B)12\(9)11748\(1B)12\(9)12144\(1B)-11" Source =+=+=+= FUNCTION AddMonths(argBaseDate,argMonthsOffset) $COPYRIGHT "Copyright (c) 2002-2005 Ray Wurlod. All rights reserved." $* May be freely used with the above copyright notice intact and the code unmodified. Equate RoutineName To "AddMonths" * Disable this token to disable warnings about first argument. $DEFINE DATECHECK * Disable this token to disable warnings about second argument. $DEFINE NUMBERCHECK * Calculate external format of passed date, integer part of MonthsOffset. MonthsOffset = Field(argMonthsOffset, ".", 1, 1) $IFDEF NUMBERCHECK If Not(Num(MonthsOffset)) Then Call DSTransformError("Months offset (" : Quote(argMonthsOffset) : ") is not numeric.", RoutineName) GoTo MainExit End $ENDIF OriginalDate = Oconv(argBaseDate, "D-YMD[4,2,2]") * If this was successful then we have a valid date and months offset. If Status() = 0 And Num(MonthsOffset) Then * Decompose original date into year, month and day components. OriginalYear = OriginalDate[1,4] OriginalMonth = OriginalDate[6,2] OriginalDay = OriginalDate[9,2] * Determine years and months by which to change date. AbsMonthsOffset = Abs(MonthsOffset) YearChange = Int(AbsMonthsOffset / 12) MonthChange = AbsMonthsOffset - (12 * YearChange) * Arithmetic is slightly different if MonthsOffset is negative. If MonthsOffset >= 0 Then NewYear = OriginalYear + YearChange NewMonth = OriginalMonth + MonthChange If NewMonth > 12 Then NewYear += 1 NewMonth -= 12 End NewDay = OriginalDay * Rewind day number until a valid date is encountered. Loop Ans = Iconv(NewYear "R%4" : "-" : NewMonth "R%2" : "-" : NewDay "R%2", "DYMD") While Status() <> 0 NewDay -= 1 Repeat End Else NewYear = OriginalYear - YearChange NewMonth = OriginalMonth - MonthChange If NewMonth < 1 Then NewYear -= 1 NewMonth += 12 End NewDay = OriginalDay * Rewind day number until a valid date is encountered. Loop Ans = Iconv(NewYear "R%4" : "-" : NewMonth "R%2" : "-" : NewDay "R%2", "DYMD") While Status() <> 0 NewDay -= 1 Repeat End End Else Ans = @NULL $IFDEF DATECHECK Call DSTransformError("Base date argument (" : Quote(argBaseDate) : ") is not a valid internal format date.", RoutineName) $ENDIF End MainExit: RETURN(Ans) =+=+=+= Catalog "DSU.AddMonths" JobType "0" PlatformType "" Arguments "CRtnArgument" BEGIN DSSUBRECORD Name "argBaseDate" Desc "Date to which MonthsOffset months are to be added" SqlType "0" ColScale "0" IOType "0" NativeType "" Nullable "0" NullValue "" Occurs "0" KeyPosition "0" Precision "0" SignIndicator "" SignOption "0" SyncIndicator "0" Usage "" DateMask "" DependField "" LevelNo "0" RedefinedField "" END DSSUBRECORD BEGIN DSSUBRECORD Name "argMonthsOffset" Desc "Number of months to add to BaseDate. May be negative. Must be integer." SqlType "1" ColScale "0" IOType "0" NativeType "" Nullable "0" NullValue "" Occurs "0" KeyPosition "0" Precision "0" SignIndicator "" SignOption "0" SyncIndicator "0" Usage "" DateMask "" DependField "" LevelNo "0" RedefinedField "" END DSSUBRECORD ExternalName "" LibraryPath "" Language "" SkipOnNull "" InvocationMethod "" RoutineJCL "" ReturnType "" END DSRECORD BEGIN DSUBINARY Identifier "DSU.AddMonths" B1 "E1DA1175050011001000030000000000240025003900390014002500000014002802000064000000" B41 "380000008C000000B75900007C0200007C020000F5030000B0050000200600000000000000000000" B81 "080000008400130015001600160001001001010017000E0117001800DE0218004800000040011300" B121 "1B00040103001A001B001C000200F8001D0003001E001900020002000300C2001802000012011200" B161 "1E0004008E0118006E0018001F0020001001010021000800200021002200DE0222000000F0010000" B201 "F0000400160023000500F0000400240025000600F00004002600250007000200010008005A000800" B241 "27002800BE002800090002012700090028009401080028000A00A00001001F002800DE0228000000" B281 "5C0100000400050009000B00040006000A000C00A6000C0027002900DE022900F800000004000B00" B321 "16000B0094010C0027000C00F80007000D009C000B002A0029009C000C002C002D009C000D002C00" B361 "2E000401050029002B002D002B002E002F00AC002F0030000E000C018E012F0006012F001F003100" B401 "DE0231005401000094010D0016000D000C01C200FE000000C2000000E80100009401050009000B00" B441 "940106000A000C00DC000C0016003100DE0231008C01000094010B0016000B0004000C0027000C00" B481 "F80007000D009C000B002A0031009C000C002C0032009C000D002C0033000401050031002B003200" B521 "2B0033003400AC00340030000E000C018E013400060134001F003500DE023500E801000094010D00" B561 "16000D000C01C20092010000C200000018020000F80014000E004001120028000401030036002800" B601 "37000F00F8001D0010001E00190002000F001000F8000E0011005C01F800380011005C01002E4453" B641 "5472616E73666F726D4572726F724D6F6E746873206F6666736574202829206973206E6F74206E75" B681 "6D657269632E4164644D6F6E746873442D594D445B342C322C325D5225342D52253244594D444261" B721 "7365206461746520617267756D656E74202829206973206E6F7420612076616C696420696E746572" B761 "6E616C20666F726D617420646174652E062B00000001010000000100000003010000000500000000" B801 "0501000000041000000002000000010F000000120000000502000000011100000021000000010900" B841 "000032000000010C0000003B00000003000000000503000000050400000005050000000304000000" B881 "030600000003020000000309000000030C0000000506000000050700000001030000004700000001" B921 "010000004A00000001030000004B00000005080000000509000000050A00000001040000004E0000" B961 "00050B000000050C000000050D000000050E000000050F0000000114000000520000000126000000" B1001 "6600000001000000008C000000000000000000000000000000080000000100010000000000150000" B1041 "0002000100000000001C000000030001000000000023000000040001000000000030000000050001" B1081 "00000000003D00000006000100000000004B00000007000100000000005700000008000100000000" B1121 "00670000000900010000000000720000000A000100000000007E0000000B00010000000000860000" B1161 "000C000100000000008F0000000D00010000000000960000000E000100000000009A0000000F0001" B1201 "0000000000A10000001000010000000000A80000001100030000000000AF00000012000400000000" B1241 "00BB0000001300040000000000244D4154524958004D6F6E7468734F6666736574005F5430303031" B1281 "005F5430303032004F726967696E616C44617465004F726967696E616C59656172004F726967696E" B1321 "616C4D6F6E7468004F726967696E616C446179004162734D6F6E7468734F66667365740059656172" B1361 "4368616E6765004D6F6E74684368616E6765004E657759656172004E65774D6F6E7468004E657744" B1401 "617900416E73005F5430303033005F5430303034005F543030303000617267426173654461746500" B1441 "6172674D6F6E7468734F666673657400EFFF0000FCFF0C00FEFF14002200FBFF0600FDFF0800FBFF" B1481 "24000A000A00FDFF0A0006000E00FDFF1000FDFF120008000800FEFF10000800FEFF0800FCFF0600" B1521 "300016000800FBFF100008000800FEFF10000800FEFF0800FCFF0600300016000800F8FF1000FDFF" B1561 "0600FAFF22000800443A5C417363656E7469616C5C4461746153746167655C50726F6A656374735C" B1601 "50726F6A314465762F4453555F42502F4453552E4164644D6F6E74687300436F7079726967687420" B1641 "28632920323030322D3230303520526179205775726C6F642E2020416C6C20726967687473207265" B1681 "7365727665642E220D00204D617920626520667265656C7920757365642077697468207468652061" B1721 "626F766520636F70797269676874206E6F7469636520696E7461637420616E642074686520636F64" B1761 "6520756E6D6F6469666965642E0D" END DSUBINARY BEGIN DSRECORD Identifier "AddMonthsToTimestamp" DateModified "2005-09-03" TimeModified "11.12.40" OLEType "CRoutine" Readonly "0" Category "Ray Wurlod\\Date" ShortDesc "Add integer number of months to a timestamp" Description =+=+=+= Input arguments: BaseDate - the timestamp, in ISO 8601 format, to which a number of months is to be added. MonthsOffset - the number of months to be added to BaseDate; must be integer, may be negative. Truncated to integer. Return value: Timestamp in ISO 8601 format represented by the arithmetic operation. Returns NULL if BaseDate is not a valid DataStage internal format date. Notes: If the obvious generated date is not legal, the day number of the result is wound back until a valid date is represented. For example, adding 4 months to 31 December will result in 30 April. =+=+=+= RoutineType "0" ArgCount "2" Built "1" SourceFlag "1" Vendor "Ray Wurlod ABN 57 092 448 518" Author "Ray Wurlod" Version "2.0.0" Copyright "Copyright (c) 2002-2005 Ray Wurlod. All rights reserved." TestValues "2005-01-01 12:34:56\(1B)1\(9)2005-01-01 12:34:56\(1B)12\(9)2005-01-01 12:34:56\(1B)-12\(9)2005-01-01 12:34:56\(1B)14\(9)2005-01-01 12:34:56.123\(1B)24\(9)2005-01-01 12:34:56.123456\(1B)24" Source =+=+=+= FUNCTION AddMonthsToTimestamp(argBaseDate,argMonthsOffset) $COPYRIGHT "Copyright (c) 2002-2005 Ray Wurlod. All rights reserved." $* May be freely used with the above copyright notice intact and the code unmodified. Equate RoutineName To "AddMonthsToTimestamp" DEFFUN AddMonths(Arg1, Arg2) Calling "DSU.AddMonths" TimestampPattern = "4N'-'2N'-'2N' '2N':'2N':'2N" * Disable this token to disable warnings about first argument. $DEFINE DATECHECK * Disable this token to disable warnings about second argument. $DEFINE NUMBERCHECK MonthsOffset = Field(argMonthsOffset, ".", 1, 1) $IFDEF NUMBERCHECK If Not(Num(MonthsOffset)) Then Call DSTransformError("Months offset (" : Quote(argMonthsOffset) : ") is not numeric.", RoutineName) Ans = @NULL GoTo MainExit End $ENDIF If Left(argBaseDate, 19) Matches TimestampPattern Then BaseDate = Iconv(Left(argBaseDate, 10), "DYMD") NewDate = Oconv(AddMonths(BaseDate, MonthsOffset), "D-YMD[4,2,2]") Ans = NewDate : argBaseDate[11, 9] If Len(argBaseDate) > 19 Then If argBaseDate[20,Len(argBaseDate)] Matches "'.'1N0N" Then Ans := argBaseDate[20, Len(argBaseDate)] End End End Else Ans = @NULL $IFDEF DATECHECK Call DSTransformError("Base date is not a valid ISO 8601 timestamp.", RoutineName) $ENDIF End MainExit: RETURN(Ans) =+=+=+= Catalog "DSU.AddMonthsToTimestamp" Dependencies "CRtnDepend" BEGIN DSSUBRECORD Name "DSU.AddMonths" Type "1" Location "" END DSSUBRECORD JobType "0" PlatformType "" Arguments "CRtnArgument" BEGIN DSSUBRECORD Name "argBaseDate" Desc "Date to which MonthsOffset months are to be added" SqlType "0" ColScale "0" IOType "0" NativeType "" Nullable "0" NullValue "" Occurs "0" KeyPosition "0" Precision "0" SignIndicator "" SignOption "0" SyncIndicator "0" Usage "" DateMask "" DependField "" LevelNo "0" RedefinedField "" END DSSUBRECORD BEGIN DSSUBRECORD Name "argMonthsOffset" Desc "Number of months to add to BaseDate. May be negative. Must be integer." SqlType "1" ColScale "0" IOType "0" NativeType "" Nullable "0" NullValue "" Occurs "0" KeyPosition "0" Precision "0" SignIndicator "" SignOption "0" SyncIndicator "0" Usage "" DateMask "" DependField "" LevelNo "0" RedefinedField "" END DSSUBRECORD ExternalName "" LibraryPath "" Language "" SkipOnNull "" InvocationMethod "" RoutineJCL "" ReturnType "" END DSRECORD BEGIN DSUBINARY Identifier "DSU.AddMonthsToTimestamp" B1 "E1DA1175050011000B000300000000001D001E002D002D000F001E00000014002801000039000000" B41 "1C000000B1000000FB7100007C0100007C010000F30200002B040000630400000000000000000000" B81 "08000000F8001000030084000E0011001200120004001001040013000E0113001400DE0214000000" B121 "5800000040010E001700040103001600170018000500F800190006001E001500020005000600F800" B161 "0F000700C20000001801000086020D001A001400E000140003001B00DE021B00FC00000086020D00" B201 "1C001D00AC001D001E00080096011F000200080004001D0012011D0020000900F0000D0021002200" B241 "1D003A0009001D000700D0000D001D00A6001D001A002300DE022300F4000000D0000D002500F000" B281 "0D00240025002600E000260027002800DE022800F4000000D0000D002900F0000D00240029002A00" B321 "3A0007002A000700C200000018010000F8000F000700F8002B000A00F80019000B001E0015000200" B361 "0A000B00F80007000C005C01F8002C000C005C0100344E272D27324E272D27324E272027324E273A" B401 "27324E273A27324E2E44535472616E73666F726D4572726F724D6F6E746873206F66667365742028" B441 "29206973206E6F74206E756D657269632E4164644D6F6E746873546F54696D657374616D7044594D" B481 "444453552E4164644D6F6E746873442D594D445B342C322C325D272E27314E304E42617365206461" B521 "7465206973206E6F7420612076616C69642049534F20383630312074696D657374616D702E062B00" B561 "0000011B0000000100000001010000001C0000000301000000050000000005010000000410000000" B601 "1D000000010F0000002D000000050200000001110000003C00000001140000004D00000003130000" B641 "000503000000030A0000000504000000010400000061000000040D00000065000000010C00000072" B681 "000000030B0000000309000000050500000003140000000506000000050700000001070000007E00" B721 "000005080000000509000000050A000000012C000000850000000100000000B10000000000000000" B761 "000000000000000800000001000100000000000D0000000200010000000000120000000300010000" B801 "0000002300000004000100000000003000000005000100000000003700000006000100000000003E" B841 "00000007000100000000004200000008000100000000004B0000000900010000000000530000000A" B881 "000100000000005A0000000B00010000000000610000000C00030000000000680000000D00040000" B921 "000000740000000E00040000000000244D4154524958004172673100417267320054696D65737461" B961 "6D705061747465726E004D6F6E7468734F6666736574005F5430303031005F543030303200416E73" B1001 "004261736544617465004E657744617465005F5430303033005F5430303034005F54303030300061" B1041 "72674261736544617465006172674D6F6E7468734F666673657400F7FF0000F5FF0600FDFF0C00FE" B1081 "FF160022000600FBFF0800FEFF1800100014001200FEFF1600FEFF2000FAFF2000FDFF0600F9FF16" B1121 "000800443A5C417363656E7469616C5C4461746153746167655C50726F6A656374735C50726F6A31" B1161 "4465762F4453555F42502F4453552E4164644D6F6E746873546F54696D657374616D7000436F7079" B1201 "72696768742028632920323030322D3230303520526179205775726C6F642E2020416C6C20726967" B1241 "6874732072657365727665642E220D00204D617920626520667265656C7920757365642077697468" B1281 "207468652061626F766520636F70797269676874206E6F7469636520696E7461637420616E642074" B1321 "686520636F646520756E6D6F6469666965642E0D" END DSUBINARY BEGIN DSRECORD Identifier "AddWeeks" DateModified "2005-09-03" TimeModified "10.32.43" OLEType "CRoutine" Readonly "0" Category "Ray Wurlod\\Date" ShortDesc "Add integer number of weeks to a date" Description =+=+=+= Input arguments: BaseDate - the date, in DataStage internal format, to which a number of weeks is to be added. MonthsOffset - the number of weeks to be added to BaseDate; must be integer, may be negative. Truncated to integer. Return value: Date in DataStage internal format represented by the arithmetic operation. Returns NULL if BaseDate is not a valid DataStage internal format date. =+=+=+= RoutineType "0" ArgCount "2" Built "1" SourceFlag "1" Vendor "Ray Wurlod ABN 57 092 448 518" Author "Ray Wurlod" Version "2.0.0" Copyright "Copyright (c) 2002-2005 Ray Wurlod. All rights reserved." TestValues "11688\(1B)1\(9)11719\(1B)1\(9)11747\(1B)1\(9)11779\(1B)1\(9)12085\(1B)1\(9)11719\(1B)-1\(9)11747\(1B)-1\(9)11748\(1B)-1\(9)11779\(1B)-1\(9)12113\(1B)-1\(9)12144\(1B)-1\(9)12174\(1B)-1\(9)12054\(1B)0\(9)11688\(1B)12\(9)11748\(1B)12\(9)12144\(1B)-11" Source =+=+=+= FUNCTION AddWeeks(argBaseDate,argWeeksOffset) $COPYRIGHT "Copyright (c) 2002-2005 Ray Wurlod. All rights reserved." $* May be freely used with the above copyright notice intact and the code unmodified. Equate RoutineName To "AddWeeks" * Disable this token to disable warnings about first argument. $DEFINE DATECHECK * Disable this token to disable warnings about second argument. $DEFINE NUMBERCHECK * Calculate integer part of WeeksOffset. WeeksOffset = Field(argWeeksOffset, ".", 1, 1) $IFDEF NUMBERCHECK If Not(Num(WeeksOffset)) Then Call DSTransformError("Weeks offset is not numeric.", RoutineName) Ans = @NULL GoTo MainExit End $ENDIF DaysOffset = WeeksOffset * 7 * Check that base date is an internal format date. If it is, do day arithmetic. * If not, return NULL. If argBaseDate Matches "1N0N" : @VM : "'-'1N0N" Then Ans = argBaseDate + DaysOffset End Else Ans = @NULL $IFDEF DATECHECK Call DSTransformError("Base date argument (" : Quote(argBaseDate) : ") is not a valid internal format date.", RoutineName) $ENDIF End MainExit: RETURN(Ans) =+=+=+= Catalog "DSU.AddWeeks" JobType "0" PlatformType "" Arguments "CRtnArgument" BEGIN DSSUBRECORD Name "argBaseDate" Desc "Date to which MonthsOffset months are to be added" SqlType "0" ColScale "0" IOType "0" NativeType "" Nullable "0" NullValue "" Occurs "0" KeyPosition "0" Precision "0" SignIndicator "" SignOption "0" SyncIndicator "0" Usage "" DateMask "" DependField "" LevelNo "0" RedefinedField "" END DSSUBRECORD BEGIN DSSUBRECORD Name "argWeeksOffset" Desc "Number of weeks to add to BaseDate. May be negative. Must be integer." SqlType "1" ColScale "0" IOType "0" NativeType "" Nullable "0" NullValue "" Occurs "0" KeyPosition "0" Precision "0" SignIndicator "" SignOption "0" SyncIndicator "0" Usage "" DateMask "" DependField "" LevelNo "0" RedefinedField "" END DSSUBRECORD ExternalName "" LibraryPath "" Language "" SkipOnNull "" InvocationMethod "" RoutineJCL "" ReturnType "" END DSRECORD BEGIN DSUBINARY Identifier "DSU.AddWeeks" B1 "E1DA1175050011000700030000000000110012001D001D000B00120000001400B800000030000000" B41 "150000007B00000082C400000C0100000C01000005020000EA020000140300000000000000000000" B81 "0800000084000A000C000D000D000100100101000E000E010E000F00DE020F0044000000F8001100" B121 "0200F800120003001E001000020002000300F8000B000400C2000000A80000000201010013000500" B161 "260015000F000401030014000F0016001700E000090017001800DE02180000008000000004000900" B201 "05000400C2000000A8000000F8000B000400400109001A000401030019001A001B000600F8001200" B241 "07001E001000020006000700F800040008005C01F8001C0008005C01002E44535472616E73666F72" B281 "6D4572726F725765656B73206F6666736574206973206E6F74206E756D657269632E416464576565" B321 "6B73314E304E272D27314E304E42617365206461746520617267756D656E74202829206973206E6F" B361 "7420612076616C696420696E7465726E616C20666F726D617420646174652E062B00000001010000" B401 "0001000000030100000005000000000501000000041000000002000000011C000000120000000108" B441 "0000002E000000030700000001040000003600000003FD00000001070000003A0000000502000000" B481 "0503000000011400000041000000050400000001260000005500000001000000007B000000000000" B521 "0000000000000000000800000001000100000000001400000002000100000000001B000000030001" B561 "00000000002200000004000100000000002600000005000100000000003100000006000100000000" B601 "003800000007000100000000003F0000000800030000000000460000000900040000000000520000" B641 "000A00040000000000244D4154524958005765656B734F6666736574005F5430303031005F543030" B681 "303200416E7300446179734F6666736574005F5430303033005F5430303034005F54303030300061" B721 "72674261736544617465006172675765656B734F666673657400EFFF0000FDFF0C00FEFF14001600" B761 "0600FDFF0800FCFF0800FDFF2400FBFF1000FDFF0600FAFF22000800443A5C417363656E7469616C" B801 "5C4461746153746167655C50726F6A656374735C50726F6A314465762F4453555F42502F4453552E" B841 "4164645765656B7300436F707972696768742028632920323030322D323030352052617920577572" B881 "6C6F642E2020416C6C207269676874732072657365727665642E220D00204D617920626520667265" B921 "656C7920757365642077697468207468652061626F766520636F70797269676874206E6F74696365" B961 "20696E7461637420616E642074686520636F646520756E6D6F6469666965642E0D" END DSUBINARY BEGIN DSRECORD Identifier "AddWeeksToTimestamp" DateModified "2005-09-03" TimeModified "11.18.47" OLEType "CRoutine" Readonly "0" Category "Ray Wurlod\\Date" ShortDesc "Add integer number of weeks to a timestamp" Description =+=+=+= Input arguments: BaseDate - the timestamp, in ISO 8601 format, to which a number of weeks is to be added. WeeksOffset - the number of weeks to be added to BaseDate; must be integer, may be negative. Truncated to integer. Return value: Timestamp in ISO 8601 format represented by the arithmetic operation. Returns NULL if BaseDate is not a valid DataStage internal format date. Notes: If the obvious generated date is not legal, the day number of the result is wound back until a valid date is represented. For example, adding 4 months to 31 December will result in 30 April. =+=+=+= RoutineType "0" ArgCount "2" Built "1" SourceFlag "1" Vendor "Ray Wurlod ABN 57 092 448 518" Author "Ray Wurlod" Version "2.0.0" Copyright "Copyright (c) 2002-2005 Ray Wurlod. All rights reserved." TestValues "2005-01-01 12:34:56\(1B)1\(9)2005-01-01 12:34:56\(1B)12\(9)2005-01-01 12:34:56\(1B)-12\(9)2005-01-01 12:34:56\(1B)14\(9)2005-01-01 12:34:56.123\(1B)24\(9)2005-01-01 12:34:56.123456\(1B)24" Source =+=+=+= FUNCTION AddWeeksToTimestamp(argBaseDate,argWeeksOffset) $COPYRIGHT "Copyright (c) 2002-2005 Ray Wurlod. All rights reserved." $* May be freely used with the above copyright notice intact and the code unmodified. Equate RoutineName To "AddWeeksToTimestamp" DEFFUN AddWeeks(Arg1, Arg2) Calling "DSU.AddWeeks" TimestampPattern = "4N'-'2N'-'2N' '2N':'2N':'2N" * Disable this token to disable warnings about first argument. $DEFINE DATECHECK * Disable this token to disable warnings about second argument. $DEFINE NUMBERCHECK WeeksOffset = Field(argWeeksOffset, ".", 1, 1) $IFDEF NUMBERCHECK If Not(Num(WeeksOffset)) Then Call DSTransformError("Weeks offset (" : Quote(argWeeksOffset) : ") is not numeric.", RoutineName) Ans = @NULL GoTo MainExit End $ENDIF If Left(argBaseDate, 19) Matches TimestampPattern Then BaseDate = Iconv(Left(argBaseDate, 10), "DYMD") NewDate = Oconv(AddWeeks(BaseDate, WeeksOffset), "D-YMD[4,2,2]") Ans = NewDate : argBaseDate[11, 9] If Len(argBaseDate) > 19 Then If argBaseDate[20,Len(argBaseDate)] Matches "'.'1N0N" Then Ans := argBaseDate[20, Len(argBaseDate)] End End End Else Ans = @NULL $IFDEF DATECHECK Call DSTransformError("Base date is not a valid ISO 8601 timestamp.", RoutineName) $ENDIF End MainExit: RETURN(Ans) =+=+=+= Catalog "DSU.AddWeeksToTimestamp" Dependencies "CRtnDepend" BEGIN DSSUBRECORD Name "DSU.AddWeeks" Type "1" Location "" END DSSUBRECORD JobType "0" PlatformType "" Arguments "CRtnArgument" BEGIN DSSUBRECORD Name "argBaseDate" Desc "Date to which WeeksOffset months are to be added" SqlType "0" ColScale "0" IOType "0" NativeType "" Nullable "0" NullValue "" Occurs "0" KeyPosition "0" Precision "0" SignIndicator "" SignOption "0" SyncIndicator "0" Usage "" DateMask "" DependField "" LevelNo "0" RedefinedField "" END DSSUBRECORD BEGIN DSSUBRECORD Name "argWeeksOffset" Desc "Number of weeks to add to BaseDate. May be negative. Must be integer. Decimal numbers are truncated." SqlType "1" ColScale "0" IOType "0" NativeType "" Nullable "0" NullValue "" Occurs "0" KeyPosition "0" Precision "0" SignIndicator "" SignOption "0" SyncIndicator "0" Usage "" DateMask "" DependField "" LevelNo "0" RedefinedField "" END DSSUBRECORD ExternalName "" LibraryPath "" Language "" SkipOnNull "" InvocationMethod "" RoutineJCL "" ReturnType "" END DSRECORD BEGIN DSUBINARY Identifier "DSU.AddWeeksToTimestamp" B1 "E1DA1175050011000B000300000000001D001E002D002D000F001E00000014002801000039000000" B41 "1C000000AE000000064A00007C0100007C010000F0020000260400005E0400000000000000000000" B81 "08000000F8001000030084000E0011001200120004001001040013000E0113001400DE0214000000" B121 "5800000040010E001700040103001600170018000500F800190006001E001500020005000600F800" B161 "0F000700C20000001801000086020D001A001400E000140003001B00DE021B00FC00000086020D00" B201 "1C001D00AC001D001E00080096011F000200080004001D0012011D0020000900F0000D0021002200" B241 "1D003A0009001D000700D0000D001D00A6001D001A002300DE022300F4000000D0000D002500F000" B281 "0D00240025002600E000260027002800DE022800F4000000D0000D002900F0000D00240029002A00" B321 "3A0007002A000700C200000018010000F8000F000700F8002B000A00F80019000B001E0015000200" B361 "0A000B00F80007000C005C01F8002C000C005C0100344E272D27324E272D27324E272027324E273A" B401 "27324E273A27324E2E44535472616E73666F726D4572726F725765656B73206F6666736574202829" B441 "206973206E6F74206E756D657269632E4164645765656B73546F54696D657374616D7044594D4444" B481 "53552E4164645765656B73442D594D445B342C322C325D272E27314E304E42617365206461746520" B521 "6973206E6F7420612076616C69642049534F20383630312074696D657374616D702E062B00000001" B561 "1B0000000100000001010000001C00000003010000000500000000050100000004100000001D0000" B601 "00010E0000002D000000050200000001110000003B00000001130000004C00000003130000000503" B641 "000000030A000000050400000001040000005F000000040C00000063000000010C0000006F000000" B681 "030B0000000309000000050500000003140000000506000000050700000001070000007B00000005" B721 "080000000509000000050A000000012C000000820000000100000000AE0000000000000000000000" B761 "000000000800000001000100000000000D0000000200010000000000120000000300010000000000" B801 "2300000004000100000000002F00000005000100000000003600000006000100000000003D000000" B841 "07000100000000004100000008000100000000004A0000000900010000000000520000000A000100" B881 "00000000590000000B00010000000000600000000C00030000000000670000000D00040000000000" B921 "730000000E00040000000000244D4154524958004172673100417267320054696D657374616D7050" B961 "61747465726E005765656B734F6666736574005F5430303031005F543030303200416E7300426173" B1001 "6544617465004E657744617465005F5430303033005F5430303034005F5430303030006172674261" B1041 "736544617465006172675765656B734F666673657400F7FF0000F5FF0600FDFF0C00FEFF16002200" B1081 "0600FBFF0800FEFF1800100014001200FEFF1600FEFF2000FAFF2000FDFF0600F9FF16000800443A" B1121 "5C417363656E7469616C5C4461746153746167655C50726F6A656374735C50726F6A314465762F44" B1161 "53555F42502F4453552E4164645765656B73546F54696D657374616D7000436F7079726967687420" B1201 "28632920323030322D3230303520526179205775726C6F642E2020416C6C20726967687473207265" B1241 "7365727665642E220D00204D617920626520667265656C7920757365642077697468207468652061" B1281 "626F766520636F70797269676874206E6F7469636520696E7461637420616E642074686520636F64" B1321 "6520756E6D6F6469666965642E0D" END DSUBINARY BEGIN DSRECORD Identifier "AddYears" DateModified "2005-09-03" TimeModified "10.32.10" OLEType "CRoutine" Readonly "0" Category "Ray Wurlod\\Date" ShortDesc "Add integer number of years to a date" Description =+=+=+= Input arguments: BaseDate - the date, in DataStage internal format, to which a number of years is to be added. MonthsOffset - the number of years to be added to BaseDate; must be integer, may be negative. Truncated to integer. Return value: Date in DataStage internal format represented by the arithmetic operation. Returns NULL if BaseDate is not a valid DataStage internal format date. =+=+=+= RoutineType "0" ArgCount "2" Built "1" SourceFlag "1" Vendor "Ray Wurlod ABN 57 092 448 518" Author "Ray Wurlod" Version "2.0.0" Copyright "Copyright (c) 2002-2005 Ray Wurlod. All rights reserved." TestValues "11688\(1B)1\(9)11719\(1B)1\(9)11747\(1B)1\(9)11779\(1B)1\(9)12085\(1B)1\(9)11719\(1B)-1\(9)11747\(1B)-1\(9)11748\(1B)-1\(9)11779\(1B)-1\(9)12113\(1B)-1\(9)12144\(1B)-1\(9)12174\(1B)-1\(9)12054\(1B)0\(9)11688\(1B)12\(9)11748\(1B)12\(9)12144\(1B)-11" Source =+=+=+= FUNCTION AddYears(argBaseDate,argYearsOffset) $COPYRIGHT "Copyright (c) 2002-2005 Ray Wurlod. All rights reserved." $* May be freely used with the above copyright notice intact and the code unmodified. Equate RoutineName To "AddYears" * Disable this token if warning messages about first argument are not required to be logged. $DEFINE DATECHECK * Disable this token if warning messages about second argument are not required to be logged. $DEFINE NUMBERCHECK * Calculate integer part of MonthsOffset. YearsOffset = Field(argYearsOffset, ".", 1, 1) $IFDEF NUMBERCHECK If Not(Num(YearsOffset)) Then Call DSTransformError("Years offset is not numeric.", RoutineName) Ans = @NULL GoTo MainExit End $ENDIF * Check that base date is an internal format date. If it is, do day arithmetic. * If not, return NULL. OriginalDate = Oconv(argBaseDate, "D-YMD[4,2,2]") If Status() = 0 Then OriginalYear = OriginalDate[1,4] OriginalMonth = OriginalDate[6,2] OriginalDay = OriginalDate[9,2] NewYear = OriginalYear + argYearsOffset NewDay = OriginalDay * Make sure that return date is valid. Loop Ans = Iconv(NewYear "R%4" : "-" : OriginalMonth : "-" : NewDay "R%2", "DYMD") While Status() <> 0 NewDay -= 1 Repeat End Else Ans = @NULL $IFDEF DATECHECK Call DSTransformError("Base date argument (" : Quote(argBaseDate) : ") is not a valid internal format date.", RoutineName) $ENDIF End MainExit: RETURN(Ans) =+=+=+= Catalog "DSU.AddYears" JobType "0" PlatformType "" Arguments "CRtnArgument" BEGIN DSSUBRECORD Name "argBaseDate" Desc "Date to which MonthsOffset months are to be added" SqlType "0" ColScale "0" IOType "0" NativeType "" Nullable "0" NullValue "" Occurs "0" KeyPosition "0" Precision "0" SignIndicator "" SignOption "0" SyncIndicator "0" Usage "" DateMask "" DependField "" LevelNo "0" RedefinedField "" END DSSUBRECORD BEGIN DSSUBRECORD Name "argYearsOffset" Desc "Number of years to add to BaseDate. May be negative. Must be integer." SqlType "1" ColScale "0" IOType "0" NativeType "" Nullable "0" NullValue "" Occurs "0" KeyPosition "0" Precision "0" SignIndicator "" SignOption "0" SyncIndicator "0" Usage "" DateMask "" DependField "" LevelNo "0" RedefinedField "" END DSSUBRECORD ExternalName "" LibraryPath "" Language "" SkipOnNull "" InvocationMethod "" RoutineJCL "" ReturnType "" END DSRECORD BEGIN DSUBINARY Identifier "DSU.AddYears" B1 "E1DA1175050011000C0003000000000019001A002A002A0010001A00000014001C0100003C000000" B41 "1E0000008700000080E300007001000070010000A9020000020400003E0400000000000000000000" B81 "0800000084000F0011001200120001001001010013000E0113001400DE02140044000000F8001600" B121 "0200F800170003001E001500020002000300F80010000400C20000000C01000012010E0018000500" B161 "8E0114006E00140019001A00DE021A00E4000000F000050012001B000600F00005001C001D000700" B201 "F00005001E001D000800040006000F000900F80008000A009C0009001F0020009C000A0022002300" B241 "04010500200021000700210023002400AC002400250004000C018E0124000601240019002600DE02" B281 "26000000DC00000094010A0012000A000C01C2008C000000C20000000C010000F800100004004001" B321 "0E002600040103002700260028000B00F80017000C001E00150002000B000C00F80004000D005C01" B361 "F80029000D005C01002E44535472616E73666F726D4572726F725965617273206F66667365742069" B401 "73206E6F74206E756D657269632E4164645965617273442D594D445B342C322C325D5225342D5225" B441 "3244594D4442617365206461746520617267756D656E74202829206973206E6F7420612076616C69" B481 "6420696E7465726E616C20666F726D617420646174652E062B000000010100000001000000030100" B521 "000005000000000501000000041000000002000000011C0000001200000001080000002E00000001" B561 "0C000000360000000300000000050200000003040000000306000000030200000003090000000103" B601 "00000042000000050300000001010000004500000001030000004600000005040000000505000000" B641 "010400000049000000050600000001140000004D0000000126000000610000000100000000870000" B681 "000000000000000000000000000800000001000100000000001400000002000100000000001B0000" B721 "00030001000000000022000000040001000000000026000000050001000000000033000000060001" B761 "00000000004000000007000100000000004E00000008000100000000005A00000009000100000000" B801 "00620000000A00010000000000690000000B00010000000000700000000C00010000000000770000" B841 "000D000300000000007E0000000E000400000000008A0000000F00040000000000244D4154524958" B881 "0059656172734F6666736574005F5430303031005F543030303200416E73004F726967696E616C44" B921 "617465004F726967696E616C59656172004F726967696E616C4D6F6E7468004F726967696E616C44" B961 "6179004E657759656172004E6577446179005F5430303033005F5430303034005F54303030300061" B1001 "726742617365446174650061726759656172734F666673657400EFFF0000FDFF0C00FEFF14001600" B1041 "0600FAFF08000800FDFF14000A000A00FEFF0A000800FCFF0600280018000800FBFF1000FDFF0600" B1081 "FAFF22000800443A5C417363656E7469616C5C4461746153746167655C50726F6A656374735C5072" B1121 "6F6A314465762F4453555F42502F4453552E416464596561727300436F7079726967687420286329" B1161 "20323030322D3230303520526179205775726C6F642E2020416C6C20726967687473207265736572" B1201 "7665642E220D00204D617920626520667265656C7920757365642077697468207468652061626F76" B1241 "6520636F70797269676874206E6F7469636520696E7461637420616E642074686520636F64652075" B1281 "6E6D6F6469666965642E0D" END DSUBINARY BEGIN DSRECORD Identifier "AddYearsToTimestamp" DateModified "2005-09-03" TimeModified "11.20.43" OLEType "CRoutine" Readonly "0" Category "Ray Wurlod\\Date" ShortDesc "Add integer number of years to a timestamp" Description =+=+=+= Input arguments: BaseDate - the timestamp, in ISO 8601 format, to which a number of years is to be added. YearsOffset - the number of weeks to be added to BaseDate; must be integer, may be negative. Truncated to integer. Return value: Timestamp in ISO 8601 format represented by the arithmetic operation. Returns NULL if BaseDate is not a valid timestamp. Notes: If the obvious generated date is not legal, the day number of the result is wound back until a valid date is represented. For example, adding 4 months to 31 December will result in 30 April. =+=+=+= RoutineType "0" ArgCount "2" Built "1" SourceFlag "1" Vendor "Ray Wurlod ABN 57 092 448 518" Author "Ray Wurlod" Version "2.0.0" Copyright "Copyright (c) 2002-2005 Ray Wurlod. All rights reserved." TestValues "2005-01-01 12:34:56\(1B)1\(9)2005-01-01 12:34:56\(1B)12\(9)2005-01-01 12:34:56\(1B)-12\(9)2005-01-01 12:34:56\(1B)14\(9)2005-01-01 12:34:56.123\(1B)24\(9)2005-01-01 12:34:56.123456\(1B)24" Source =+=+=+= FUNCTION AddYearsToTimestamp(argBaseDate,argYearsOffset) $COPYRIGHT "Copyright (c) 2002-2005 Ray Wurlod. All rights reserved." $* May be freely used with the above copyright notice intact and the code unmodified. Equate RoutineName To "AddYearsToTimestamp" DEFFUN AddYears(Arg1, Arg2) Calling "DSU.AddYears" TimestampPattern = "4N'-'2N'-'2N' '2N':'2N':'2N" * Disable this token to disable warnings about first argument. $DEFINE DATECHECK * Disable this token to disable warnings about second argument. $DEFINE NUMBERCHECK YearsOffset = Field(argYearsOffset, ".", 1, 1) $IFDEF NUMBERCHECK If Not(Num(YearsOffset)) Then Call DSTransformError("Years offset (" : Quote(argYearsOffset) : ") is not numeric.", RoutineName) Ans = @NULL GoTo MainExit End $ENDIF If Left(argBaseDate, 19) Matches TimestampPattern Then BaseDate = Iconv(Left(argBaseDate, 10), "DYMD") NewDate = Oconv(AddYears(BaseDate, YearsOffset), "D-YMD[4,2,2]") Ans = NewDate : argBaseDate[11, 9] If Len(argBaseDate) > 19 Then If argBaseDate[20,Len(argBaseDate)] Matches "'.'1N0N" Then Ans := argBaseDate[20, Len(argBaseDate)] End End End Else Ans = @NULL $IFDEF DATECHECK Call DSTransformError("Base date is not a valid ISO 8601 timestamp.", RoutineName) $ENDIF End MainExit: RETURN(Ans) =+=+=+= Catalog "DSU.AddYearsToTimestamp" Dependencies "CRtnDepend" BEGIN DSSUBRECORD Name "DSU.AddYears" Type "1" Location "" END DSSUBRECORD JobType "0" PlatformType "" Arguments "CRtnArgument" BEGIN DSSUBRECORD Name "argBaseDate" Desc "Date to which YearsOffset months are to be added" SqlType "0" ColScale "0" IOType "0" NativeType "" Nullable "0" NullValue "" Occurs "0" KeyPosition "0" Precision "0" SignIndicator "" SignOption "0" SyncIndicator "0" Usage "" DateMask "" DependField "" LevelNo "0" RedefinedField "" END DSSUBRECORD BEGIN DSSUBRECORD Name "argYearsOffset" Desc "Number of years to add to BaseDate. May be negative. Must be integer. Decimal numbers are truncated." SqlType "1" ColScale "0" IOType "0" NativeType "" Nullable "0" NullValue "" Occurs "0" KeyPosition "0" Precision "0" SignIndicator "" SignOption "0" SyncIndicator "0" Usage "" DateMask "" DependField "" LevelNo "0" RedefinedField "" END DSSUBRECORD ExternalName "" LibraryPath "" Language "" SkipOnNull "" InvocationMethod "" RoutineJCL "" ReturnType "" END DSRECORD BEGIN DSUBINARY Identifier "DSU.AddYearsToTimestamp" B1 "E1DA1175050011000B000300000000001D001E002D002D000F001E00000014002801000039000000" B41 "1C000000AE000000D7A200007C0100007C010000F0020000260400005E0400000000000000000000" B81 "08000000F8001000030084000E0011001200120004001001040013000E0113001400DE0214000000" B121 "5800000040010E001700040103001600170018000500F800190006001E001500020005000600F800" B161 "0F000700C20000001801000086020D001A001400E000140003001B00DE021B00FC00000086020D00" B201 "1C001D00AC001D001E00080096011F000200080004001D0012011D0020000900F0000D0021002200" B241 "1D003A0009001D000700D0000D001D00A6001D001A002300DE022300F4000000D0000D002500F000" B281 "0D00240025002600E000260027002800DE022800F4000000D0000D002900F0000D00240029002A00" B321 "3A0007002A000700C200000018010000F8000F000700F8002B000A00F80019000B001E0015000200" B361 "0A000B00F80007000C005C01F8002C000C005C0100344E272D27324E272D27324E272027324E273A" B401 "27324E273A27324E2E44535472616E73666F726D4572726F725965617273206F6666736574202829" B441 "206973206E6F74206E756D657269632E4164645965617273546F54696D657374616D7044594D4444" B481 "53552E4164645965617273442D594D445B342C322C325D272E27314E304E42617365206461746520" B521 "6973206E6F7420612076616C69642049534F20383630312074696D657374616D702E062B00000001" B561 "1B0000000100000001010000001C00000003010000000500000000050100000004100000001D0000" B601 "00010E0000002D000000050200000001110000003B00000001130000004C00000003130000000503" B641 "000000030A000000050400000001040000005F000000040C00000063000000010C0000006F000000" B681 "030B0000000309000000050500000003140000000506000000050700000001070000007B00000005" B721 "080000000509000000050A000000012C000000820000000100000000AE0000000000000000000000" B761 "000000000800000001000100000000000D0000000200010000000000120000000300010000000000" B801 "2300000004000100000000002F00000005000100000000003600000006000100000000003D000000" B841 "07000100000000004100000008000100000000004A0000000900010000000000520000000A000100" B881 "00000000590000000B00010000000000600000000C00030000000000670000000D00040000000000" B921 "730000000E00040000000000244D4154524958004172673100417267320054696D657374616D7050" B961 "61747465726E0059656172734F6666736574005F5430303031005F543030303200416E7300426173" B1001 "6544617465004E657744617465005F5430303033005F5430303034005F5430303030006172674261" B1041 "7365446174650061726759656172734F666673657400F7FF0000F5FF0600FDFF0C00FEFF16002200" B1081 "0600FBFF0800FEFF1800100014001200FEFF1600FEFF2000FAFF2000FDFF0600F9FF16000800443A" B1121 "5C417363656E7469616C5C4461746153746167655C50726F6A656374735C50726F6A314465762F44" B1161 "53555F42502F4453552E4164645965617273546F54696D657374616D7000436F7079726967687420" B1201 "28632920323030322D3230303520526179205775726C6F642E2020416C6C20726967687473207265" B1241 "7365727665642E220D00204D617920626520667265656C7920757365642077697468207468652061" B1281 "626F766520636F70797269676874206E6F7469636520696E7461637420616E642074686520636F64" B1321 "6520756E6D6F6469666965642E0D" END DSUBINARY BEGIN DSRECORD Identifier "FinalDelimitedSubstring" DateModified "2005-09-03" TimeModified "10.54.12" OLEType "CRoutine" Readonly "0" Category "Ray Wurlod\\String" ShortDesc "Returns the rightmost delimited substring of a string" Description =+=+=+= Input Arguments SourceString - String from which the rightmost delimited substring is to be extracted. Delimiter - Single character that delimits substrings in SourceString. Returns the rightmost delimited substring of SourceString. If Delimiter is empty ("") returns the rightmost character of SourceString. If Delimiter contains more than one character, the first character is used. If either argument is null or unassigned, returns null. =+=+=+= RoutineType "0" ArgCount "2" Built "1" SourceFlag "1" Vendor "Ray Wurlod ABN 57 092 448 518" Author "Ray Wurlod" Version "2.0.0" Copyright "Copyright (c) 2002-2005 Ray Wurlod. All rights reserved." TestValues "Mon,Tue,Wed,Thu,Fri\(1B),\(9)Mon,Tue,Wed,Thu,Fri,Sat,Sun\(1B),\(9)Europe|Asia|Africa|Australia|North America|South America\(1B)|\(9)Whelan the Wrecker\(1B)\(9)HappyxSleepyxGrumpyxDopeyxSneezyxDoc\(1B)xyz" Source =+=+=+= FUNCTION FinalDelimitedSubstring(argSourceString,argDelimiter) $COPYRIGHT "Copyright (c) 2002-2005 Ray Wurlod. All rights reserved." $* May be freely used with the above copyright notice intact and the code unmodified. Equate RoutineName To "FinalDelimitedSubstring" $DEFINE REPORTNULLARG * Ensure both arguments have values If UnAssigned(argSourceString) Or IsNull(argSourceString) Or UnAssigned(argDelimiter) Or IsNull(argDelimiter) Then Ans = @NULL $IFDEF REPORTNULLARG Call DSLogWarn("Unassigned or null argument.", RoutineName) $ENDIF End Else * If delimiter is empty, return rightmost character. If argDelimiter = "" Then Ans = Right(argSourceString, 1) End Else * If delimiter contains more than one character, only the first character is used. Delimiter = Left(argDelimiter, 1) FinalField = DCount(argSourceString, Delimiter) Ans = Field(argSourceString, Delimiter, FinalField, 1) End End RETURN(Ans) =+=+=+= Catalog "DSU.FinalDelimitedSubstring" JobType "0" PlatformType "" Arguments "CRtnArgument" BEGIN DSSUBRECORD Name "argSourceString" Desc "String from which the rightmost delimited substring is to be extracted." SqlType "0" ColScale "0" IOType "0" NativeType "" Nullable "0" NullValue "" Occurs "0" KeyPosition "0" Precision "0" SignIndicator "" SignOption "0" SyncIndicator "0" Usage "" DateMask "" DependField "" LevelNo "0" RedefinedField "" END DSSUBRECORD BEGIN DSSUBRECORD Name "argDelimiter" Desc "Single character that delimits substrings in SourceString." SqlType "1" ColScale "0" IOType "0" NativeType "" Nullable "0" NullValue "" Occurs "0" KeyPosition "0" Precision "0" SignIndicator "" SignOption "0" SyncIndicator "0" Usage "" DateMask "" DependField "" LevelNo "0" RedefinedField "" END DSSUBRECORD ExternalName "" LibraryPath "" Language "" SkipOnNull "" InvocationMethod "" RoutineJCL "" ReturnType "" END DSRECORD BEGIN DSUBINARY Identifier "DSU.FinalDelimitedSubstring" B1 "E1DA11750500110005000300000000000D000E001700170009000E0000001400A80000002A000000" B41 "120000003D000000466E0000FC000000FC0000008F0100004E020000720200000000000000000000" B81 "08000000AE0207000A00C40207000B0022010A000B000C00AE0208000D0022010C000D000E00C402" B121 "08000F0022010E000F001000DE0210005C000000F80009000100F80012000200F800130003001E00" B161 "1100020002000300C2000000980000006E00080014001500DE0215007C0000006401070016000100" B201 "C20000009800000086020800160004005000070004000500840007000400050016000100F8000100" B241 "06005C01F800140006005C010044534C6F675761726E556E61737369676E6564206F72206E756C6C" B281 "20617267756D656E742E46696E616C44656C696D69746564537562737472696E67062B0000000500" B321 "00000005010000000502000000050300000005040000000505000000050600000004090000000100" B361 "0000011C0000000A00000001170000002600000001000000003D0000000507000000030100000000" B401 "00000000000000000000000800000001000100000000000C00000002000100000000001300000003" B441 "000100000000001A00000004000100000000002400000005000100000000002F0000000600030000" B481 "000000360000000700040000000000460000000800040000000000244D415452495800416E73005F" B521 "5430303031005F54303030320044656C696D697465720046696E616C4669656C64005F5430303030" B561 "00617267536F75726365537472696E670061726744656C696D6974657200F4FF0000FDFF3800FDFF" B601 "0600F9FF1E00FDFF1000FAFF1000FEFF08000800FBFF0C000800443A5C417363656E7469616C5C44" B641 "61746153746167655C50726F6A656374735C50726F6A314465762F4453555F42502F4453552E4669" B681 "6E616C44656C696D69746564537562737472696E6700436F70797269676874202863292032303032" B721 "2D3230303520526179205775726C6F642E2020416C6C207269676874732072657365727665642E22" B761 "0D00204D617920626520667265656C7920757365642077697468207468652061626F766520636F70" B801 "797269676874206E6F7469636520696E7461637420616E642074686520636F646520756E6D6F6469" B841 "666965642E0D" END DSUBINARY END DSROUTINES