All files / src/git zcl_abapgit_git_time.clas.abap

100% Statements 100/100
100% Branches 0/0
100% Functions 0/0
100% Lines 100/100

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1011x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
CLASS zcl_abapgit_git_time DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .
 
  PUBLIC SECTION.
 
    TYPES:
      ty_unixtime TYPE c LENGTH 16 .
 
    CLASS-METHODS get_unix
      RETURNING
        VALUE(rv_time) TYPE ty_unixtime
      RAISING
        zcx_abapgit_exception .
 
    CLASS-METHODS get_one_year_ago
      RETURNING
        VALUE(rv_time) TYPE i
      RAISING
        zcx_abapgit_exception .
 
    CLASS-METHODS get_utc
      IMPORTING
        !iv_unix TYPE ty_unixtime
      EXPORTING
        !ev_date TYPE sy-datum
        !ev_time TYPE sy-uzeit .
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.
 
 
 
CLASS zcl_abapgit_git_time IMPLEMENTATION.
 
 
  METHOD get_one_year_ago.
* https://www.epochconverter.com
    CONSTANTS lc_epoch TYPE timestamp VALUE '19700101000000'.
    DATA lv_time TYPE timestamp.
 
    GET TIME STAMP FIELD lv_time.
 
    rv_time = cl_abap_tstmp=>subtract(
      tstmp1 = lv_time
      tstmp2 = lc_epoch ).
 
    rv_time = rv_time - 31536000.
  ENDMETHOD.
 
 
  METHOD get_unix.
* returns seconds since Unix epoch, including timezone indicator
 
    CONSTANTS lc_epoch TYPE timestamp VALUE '19700101000000'.
    DATA lv_time TYPE timestamp.
    DATA lv_seconds TYPE i.
 
    GET TIME STAMP FIELD lv_time.
 
    lv_seconds = cl_abap_tstmp=>subtract(
      tstmp1 = lv_time
      tstmp2 = lc_epoch ).
 
    rv_time = lv_seconds.
    CONDENSE rv_time.
    rv_time+11 = '+000000'.
 
  ENDMETHOD.
 
 
  METHOD get_utc.
 
    CONSTANTS lc_epoch TYPE d VALUE '19700101'.
 
    DATA: lv_i       TYPE i,
          lv_utcdiff TYPE t,
          lv_utcsign TYPE c LENGTH 1.
 
 
    lv_i = iv_unix(10).
    lv_utcsign = iv_unix+11.
    lv_utcdiff = iv_unix+12.
 
    " GMT + time-zone
    CASE lv_utcsign.
      WHEN '+'.
        lv_i = lv_i + lv_utcdiff.
      WHEN '-'.
        lv_i = lv_i - lv_utcdiff.
    ENDCASE.
 
    ev_time = lv_i MOD 86400.
    lv_i = lv_i - ev_time.
    lv_i = lv_i / 86400.
    ev_date = lv_i + lc_epoch.
 
  ENDMETHOD.
ENDCLASS.