SUBROUTINE DEFAULT.CENTURY.PIVOT(DATE1,DATE2)
* call this from a program or run it from tcl as:
* ;CALL DEFAULT.CENTURY.PIVOT("01/01/1930","12/31/2029")
* The default window will be set, and activated for the current process.
* Other existing process will have to log off and back on before the
* default takes effect.
*******************************************************
DATEDIF=46385 ;* This is the difference between an mv date and a cos date.
StartDate=iconv(DATE1,'d')+DATEDIF
EndDate=iconv(DATE2,'d')+DATEDIF
x=$function("SetDefDateWindow^%DATE",StartDate,EndDate)
crt 'old default was ':oconv(x['^',1,1]-DATEDIF,'d4/'):' to
':oconv(x['^',2,1]-DATEDIF,'d4/')
x=$function("UseDefWindow^%DATE")
crt 'old process window was ':oconv(x['^',1,1]-DATEDIF,'d4/'):' to
':oconv(x['^',2,1]-DATEDIF,'d4/')
RETURN
RN
http://groups.google.com/group/InterSystems-MV/web?hl=en
Would you be willing to write this up as an Article so that the code
isn't lost in the mailing list archives? If you have any questions as
to how to do this, please don't hesitate to ask.
Thanks!!
Ben
Robert tasked Andreas with defining the spec to front this with a
class. Andreas has said he will have a draft ready by next week. I think
you should hold off a tad.
<G>
Also, my results showed that this setting is lost on Caché restart, and so the call is required as part of system startup.
MultiValue CENTURY.PIVOT uses the existing Caché sliding 100-year window for 2-digit years, but just for the current process.
This can be set system-wide (at system startup or later) or for individual processes.
The code and doc is for Class %SYS.Date.SlidingWindow
To see the class doc, from Caché main doc page, click 'Class Reference' at the top, then on the left, 'System classes' should be checked; then part way down the left, click '%SYS', then 'Date', then 'SlidingWindow'.
There are many methods described. You can change the 100 year sliding window for 2-digit years system-wide, and/or for individual processes. If a single setting will work for all processes, you only need to set it system-wide one-time, as part of the system start process. This also affects tasks scheduled by the Caché Task Scheduler.
The Doc includes example:
Set status=##class(%SYS.Date.SlidingWindow).SetRelative(1,90,10)
This sets a relative window from 90 years ago to 10 years in the future
It also allows a call like:
Set status=##class(%SYS.Date.SlidingWindow).SetAbsolute(0,1930,2029)
This sets the window from 1/1/1930 to 12/31/2029
I changed the first arg above from 1 (process specific) to 0 (permanant, system-wide).
I did this from TCL, but you can use similar syntax for COS or MV objects calls.
* Here is what I did to test.
* First confirm that '09' is not 2009 by default.
MV:CENTURY.PIVOT
[150] Two digit years default to the years 1900 to 1999.
MV:;print oconv(15000,"d4")
24 JAN 2009
MV:;print iconv("24 JAN 2009","d")
15000
MV:;print iconv("24 JAN 09","d")
-21525
MV:
MV:[Set status=##class(%SYS.Date.SlidingWindow).SetRelative(0,90,10)
MV:[w status
1
MV:CENTURY.PIVOT
[151] Two digit years are set at the system level to the dates between01 Jan 1920 and 31 Dec 2019.
* open a new Terminal session and confirm the desired result ('09' IS 2009).
MV:;print iconv("24 JAN 09","d")
15000
MV:;print iconv("24 JAN 2009","d")
15000
MV: