class zcl_date_tools definition
public
abstract
create public .
public section.
class-methods:
formatdate
importing
date type dats
language type sylangu default sy-langu
format type csequence
returning value(result) type string,
w
importing
date type dats
language type sylangu default sy-langu
returning value(result) type string,
m
importing
date type dats
language type sylangu default sy-langu
returning value(result) type string,
daysofweek
importing
language type sylangu default sy-langu
returning value(result) type isu_t_days,
mediumformat
importing
language type sylangu default sy-langu
returning value(result) type string,
longformat
importing
language type sylangu default sy-langu
returning value(result) type string.
protected section.
private section.
class-methods:
allbutlasttwo
importing
text type csequence
returning value(resultado) type string,
lasttwo
importing
text type csequence
returning value(resultado) type text02.
endclass.
class zcl_date_tools implementation.
method formatdate.
data: position type i,
element type string.
if format cs 'ww' or format cs 'WW'.
data(w) = w( date = date language = language ).
endif.
if format cs 'mm' or format cs 'MM'.
data(m) = m( date = date language = language ).
endif.
do strlen( format ) times.
position = sy-index - 1.
concatenate element format+position(1) into element respecting blanks.
data(beginswith) = allbutlasttwo( element ).
data(endswith) = lasttwo( element ).
case endswith.
when 'dd'.
result = |{ result }{ beginswith }{ date+6(2) }|.
when 'nn'.
result = |{ result }{ beginswith }{ date+4(2) }|.
when 'mm'.
result = |{ result }{ beginswith }{ m(3) }|.
when 'MM'.
result = |{ result }{ beginswith }{ m+4 }|.
when 'yy'.
result = |{ result }{ beginswith }{ date+2(2) }|.
when 'YY'.
result = |{ result }{ beginswith }{ date(4) }|.
when 'ww'.
result = |{ result }{ beginswith }{ w(2) }|.
when 'WW'.
result = |{ result }{ beginswith }{ w+3 }|.
when others.
continue.
endcase.
free element.
enddo.
endmethod.
method w.
data: long type t246-langt,
short type t246-kurzt.
call function 'GET_WEEKDAY_NAME'
exporting
date = date
language = language
importing
longtext = long
shorttext = short
exceptions
calendar_id = 1
date_error = 2
not_found = 3
wrong_input = 4
others = 5.
if sy-subrc <> 0.
return.
endif.
result = |{ short }-{ long }|.
endmethod.
method m.
data: months type standard table of t247 with empty key.
call function 'MONTH_NAMES_GET'
exporting
language = language
tables
month_names = months
exceptions
month_names_not_found = 1
others = 2.
if sy-subrc <> 0.
return.
endif.
result = |{ months[ date+4(2) ]-ktx }-{ months[ date+4(2) ]-ltx }|.
endmethod.
method daysofweek.
call function 'WEEKDAY_GET'
exporting
language = language
tables
weekday = result.
endmethod.
method lasttwo.
check strlen( text ) >= 2.
data(start) = strlen( text ) - 2.
resultado = text+start.
endmethod.
method allbutlasttwo.
check strlen( text ) >= 2.
data(length) = strlen( text ) - 2.
resultado = text(length).
endmethod.
method mediumformat.
case language.
when 'S' or 'ES'. "26 de julio de 2021
result = 'dd de MM de YY'.
when 'E' or 'EN'. "July 26, 2021
result = 'MM dd, YY'.
when 'L' or 'PL'. "26 lipca 2021
result = 'dd MM YY'.
when '느' or '1P'. "26 de julho de 2021
result = 'dd de MM de YY'.
when '4' or 'RO'. "26 iulie 2021
result = 'dd de MM de YY'.
when 'F' or 'FR'. "26 juillet 2021
result = 'dd MM YY'.
endcase.
endmethod.
method longformat.
case language.
when 'S' or 'ES'. "sábado, 26 de julio de 2021
result = 'WW, dd de MM de YY'.
when 'E' or 'EN'. "Saturday, July 26, 2021
result = 'WW, MM dd, YY'.
when 'L' or 'PL'. "sobota, 26 lipca 2021
result = 'WW, dd MM YY'.
when '느' or '1P'. "Sábado, 26 de julho de 2021
result = 'WW, dd de MM de YY'.
when '4' or 'RO'. "Sâmbătă, 26 iulie 2021
result = 'WW, dd de MM de YY'.
when 'F' or 'FR'. "samedi 26 juillet 2021
result = 'WW dd MM YY'.
endcase.
endmethod.
endclass.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
4 | |
4 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 |