Skip to content

Commit

Permalink
new label_date should give good results in most cases, even if some k…
Browse files Browse the repository at this point in the history
…eywords are not yet supported.
  • Loading branch information
GillesDuvert committed Oct 18, 2023
1 parent 78937f8 commit 4969e6f
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions src/pro/label_date.pro
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,19 @@ FUNCTION LABEL_DATE, axis, index, x, level, DATE_FORMAT = format, MONTHS = month
;-

COMMON label_date_com, fmt, month_chr

if n_elements(fmt) eq 0 then fmt='%W %M %D %H:%I:%S %Y'
if n_elements(month_chr) eq 0 then month_chr = ['Jan','Feb','Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']

if keyword_set(months) then begin
if n_elements(months) eq 12 then month_chr = months

if keyword_set(format) then begin ;Save format string?
if keyword_set(months) then month_chr = months else month_chr = ['Jan','Feb','Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
fmt = format
return, 0
endif

if keyword_set(format) then fmt = format

IF (n_elements(level) lt 1) then level = 0

if n_elements(month_chr) ne 12 or n_elements(fmt) le 0 then $
message,' Not initialized.'

caldat, long(x), month, day, year, hour , minute , second ;Get the calendar date from julian
caldat, long(x), month, day, year ;Get the calendar date from julian
n = strlen(fmt[level])
out = ''

Expand All @@ -79,19 +78,14 @@ for i=0, n-1 do begin ;Each format character...
if c eq '%' then begin
i = i + 1
c = strmid(fmt[level], i, 1) ;The function
case c of ;format character?
'M' : out += month_chr(month-1)
'N' : out += string(format='(i2.2)', month)
'D' : out += string(format='(i2.2)', day)
'Y' : out += string(format='(i5)', year)
'Z' : out += string(format='(i3.3)', year mod 100)
'W' : ;
'A' : out += (hour gt 12) ? 'PM':'AM'
'H' : out = out + string(format='(i2.2)', hour)
'I' : out = out + string(format='(i2.2)', minute)
'S' : out = out + string(format='(i2.2)', fix(second))
case c of ;format character?
'M' : out = out + month_chr(month-1)
'N' : out = out + string(format='(i2.2)', month)
'D' : out = out + string(format='(i2.2)', day)
'Y' : out = out + string(format='(i4)', year)
'Z' : out = out + string(format='(i2.2)', year mod 100)
'%' : out = out + '%'
else : out = out + ""
else : message, 'Illegal character in date format string: '+fmt[level]
endcase
endif else out = out + c
endfor
Expand Down

0 comments on commit 4969e6f

Please sign in to comment.