comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » A routine for converting 2-digit years.
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
A routine for converting 2-digit years. [message #17225] Mon, 20 September 1999 00:00
Ray Sterner is currently offline  Ray Sterner
Messages: 10
Registered: December 1997
Junior Member
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
&nbsp;
<br>&nbsp; There may be a number of routines like this floating around,
but here is another one.
<br>&nbsp; Two digit years may be politically incorrect right now, but
they'll soon be back in use
<br>&nbsp; so a good way to deal with them is useful.&nbsp; The routine
below is very simple but should
<br>&nbsp; not break any time soon (I&nbsp;think it might have a problem
when years need more than 16
<br>&nbsp; bit integers, but it will be easy to fix and there is time to
worry about that later).&nbsp; I&nbsp;included
<br>&nbsp; a keyword to give a base year so 500 years from now somebody
could deal with 2 digit years
<br>&nbsp; from the mid-twentieth century without a lot of trouble.
<p>&nbsp; One of these days I'll try to get my IDL&nbsp;library updated.&nbsp;
I&nbsp;thought this routine might be useful
<br>&nbsp; right now.
<pre>--&nbsp;

&nbsp; Ray Sterner&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&am p;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&am p;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&am p;nbsp;&nbsp;&nbsp; sterner@tesla.jhuapl.edu&nbsp;
&nbsp; The Johns Hopkins University&nbsp;&nbsp;&nbsp; North latitude 39.16 degrees.
&nbsp; Applied Physics Laboratory&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; West longitude 76.90 degrees.
&nbsp; Laurel, MD 20723-6099</pre>

<pre> ------------------------------------------------------------ ------------ </pre>

<pre> ;----------------------------------------------------------- --
;+
; NAME:
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ; YY2YYYY
; PURPOSE:
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ; Convert a 2 digit year to a 4 digit year.
; CATEGORY:
; CALLING SEQUENCE:
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ; yyyy = yy2yyyy( yy)
; INPUTS:
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ; yy = 2 digit year.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp; in
; KEYWORD PARAMETERS:
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ; Keywords:
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp; /PAST means 4 digit year is current or past.
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp; Use this for birthdates or any dates known to be past.
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp; By default closest 4 digit year is returned.
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp; BASE=base&nbsp; Use the year given in base instead of the
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp; current year to figure out the 4 digit years.
; OUTPUTS:
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ; yyyy = 4 digit year.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp; out
; COMMON BLOCKS:
; NOTES:
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ; Notes: 2 digit years will always be useful, so a
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp; good way to convert them to 4 digit years is also
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp; useful.&nbsp; This routine should not break in the future.
; MODIFICATION HISTORY:
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ; R. Sterner, 1999 Aug 2
;
; Copyright (C) 1999, Johns Hopkins University/Applied Physics Laboratory
; This software may be used, copied, or redistributed as long as it is not
; sold and this copyright notice is reproduced on each copy made.&nbsp; This
; routine is provided as is without any express or implied warranties
; whatsoever.&nbsp; Other limitations apply as described in the file disclaimer.txt.
;-
;----------------------------------------------------------- --
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; function yy2yyyy, yy0, past=past, base=base, help=hlp
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; if (n_params(0) lt 1) or keyword_set(hlp) then begin
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print,' Convert a 2 digit year to a 4 digit year.'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print,' yyyy = yy2yyyy( yy)'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print,'&nbsp;&nbsp; yy = 2 digit year.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp; in'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print,'&nbsp;&nbsp; yyyy = 4 digit year.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp; out'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print,' Keywords:'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print,'&nbsp;&nbsp; /PAST means 4 digit year is current or past.'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print,'&nbsp;&nbsp;&nbsp;&nbsp; Use this for birthdates or any dates known to be past.'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print,'&nbsp;&nbsp;&nbsp;&nbsp; By default closest 4 digit year is returned.'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print,'&nbsp;&nbsp; BASE=base&nbsp; Use the year given in base instead of the'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print,'&nbsp;&nbsp;&nbsp;&nbsp; current year to figure out the 4 digit years.'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print,' Notes: 2 digit years will always be useful, so a'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print,'&nbsp; good way to convert them to 4 digit years is also'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print,'&nbsp; useful.&nbsp; This routine should not break in the future.'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return,''
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; endif
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; yy = yy0 + 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp; ; Force input to be numeric.
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ;----------------------------------------------------------- --
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ;&nbsp; Find current year (or working year from BASE)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ;----------------------------------------------------------- --
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; if n_elements(base) ne 0 then begin
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; yn = base+0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& ;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& ;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& ;nbsp;&nbsp;&nbsp; ; Work with year given in base.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; endif else begin
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; t = systime()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp; ; Current time.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; yn = strmid(t,strlen(t)-4,4)+0&nbsp; ; Pick off year.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; endelse
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ;----------------------------------------------------------- --
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ;&nbsp; Current century
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ;----------------------------------------------------------- --
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; cn = 100*fix(yn/100)&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp; ; Current century.
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ;----------------------------------------------------------- --
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ;&nbsp; Make list of potential centuries
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ;----------------------------------------------------------- --
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; list = [cn-100,cn]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp; ; List of last and current centuries.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; if not keyword_set(past) then $&nbsp;&nbsp; ; If not restricted to past years
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; list = [cn+100,list]&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp; ;&nbsp;&nbsp; then include next century.
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ;----------------------------------------------------------- --
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ;&nbsp; Set up storage for output
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ;----------------------------------------------------------- --
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; yy4 = yy&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp; ; Copy input to output variable.
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ;----------------------------------------------------------- --
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ;&nbsp; Loop through all input years
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ;----------------------------------------------------------- --
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; for i=0,n_elements(yy)-1 do begin
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; t = yy(i)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; Grab i'th year.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if t lt 100 then begin&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp; ; 2 digits?
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lst = list + t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp; ; Possible 4 digit years.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = abs(yn-lst)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp; ; Years away from now.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; w = where(d eq min(d))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&am p;nbsp;&nbsp; ; Look for closest to now (or base).
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t = lst(w(0))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; Pull it from list.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; endif
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; yy4(i) = t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp; ; Insert 4 digit year.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; endfor
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; return, yy4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp; ; Return 4 digit year.
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; end</pre>

<pre></pre>
</html>
[Message index]
 
Read Message
Previous Topic: Y10K
Next Topic: Re: Solaris 2.6, gcc 8.0, IDL 5.2

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 14:54:44 PDT 2025

Total time taken to generate the page: 0.95972 seconds