Advertisement
sezenspessa

EMTIME-CONVERTER

Dec 23rd, 2019
3,767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
COBOL 4.04 KB | None | 0 0
  1.       ******************************************************************
  2.       * Author: Sezen
  3.       * Date:   12/23/2019 (Edit: 4/18/2020)
  4.       ******************************************************************
  5.       * OUTPUTS:
  6.       * STANDARD TIME: 15:55:15
  7.       * EMILY TIME:    35:51:42
  8.       ******************************************************************
  9.       * MORE ON EMILY TIME:
  10.       * http://xahlee.info/kbd/happy_hacking_emily.html
  11.       ******************************************************************
  12.        IDENTIFICATION DIVISION.
  13.        PROGRAM-ID. EMTIME-CONVERTER.
  14.        ENVIRONMENT DIVISION.
  15.        CONFIGURATION SECTION.
  16.        REPOSITORY.
  17.             FUNCTION ALL INTRINSIC.
  18.        DATA DIVISION.
  19.        FILE SECTION.
  20.        WORKING-STORAGE SECTION.
  21.        01   WS-STANDARD-TIME.
  22.             05   WS-STANDARD-HOUR   PIC 99.
  23.                  88   HOUR-CHECK    VALUE 00 THRU 23.
  24.             05   COL1               PIC X VALUE ':'.
  25.             05   WS-STANDARD-MINUTE PIC 99.
  26.                  88   MIN-CHECK     VALUE 00 THRU 59.
  27.             05   COL2               PIC X VALUE ':'.
  28.             05   WS-STANDARD-SECOND PIC 99.
  29.                  88   SEC-CHECK     VALUE 00 THRU 59.
  30.        01   WS-EM-TIME.
  31.             05   WS-EM-HOUR         PIC 9(2).
  32.             05                      PIC X VALUE ':'.
  33.             05   WS-EM-MINUTE       PIC 9(2).
  34.             05                      PIC X VALUE ':'.
  35.             05   WS-EM-SECOND       PIC 9(2).
  36.        01   EM-TIME-TOTAL           PIC 99999 VALUE 46656.
  37.        01   STANDARD-TIME-TOTAL     PIC 99999 VALUE 86400.
  38.        01   DAY-PERCENT             PIC 9V9(25).
  39.        01   EM-DAY-VAL              PIC 99999.
  40.        01   DAY-SECONDS             PIC 9(6).
  41.  
  42.  
  43.  
  44.        PROCEDURE DIVISION.
  45.             DISPLAY 'Enter HH:MM:SS: '.
  46.             ACCEPT WS-STANDARD-TIME.
  47.       *    CHECK IF VALID...
  48.             IF NOT (HOUR-CHECK AND MIN-CHECK AND SEC-CHECK AND (
  49.       -    COL1 AND COL2 = ':'))
  50.             THEN
  51.                DISPLAY 'INVALID TIME ENTERED. TRY AGAIN :)'
  52.                STOP RUN
  53.             END-IF.
  54.             COMPUTE DAY-SECONDS = ((WS-STANDARD-HOUR*60)*60)+(WS-STANDAR
  55.       -    D-MINUTE*60)+WS-STANDARD-SECOND.
  56.             COMPUTE DAY-PERCENT =  DAY-SECONDS / STANDARD-TIME-TOTAL.
  57.             COMPUTE EM-DAY-VAL = EM-TIME-TOTAL * DAY-PERCENT.
  58.             COMPUTE WS-EM-HOUR = (EM-DAY-VAL / (36*36)).
  59.             COMPUTE WS-EM-MINUTE = (EM-DAY-VAL - (WS-EM-HOUR * (36 * 36
  60.       -    ))) / 36.
  61.             MOVE MOD(EM-DAY-VAL, 36) TO WS-EM-SECOND.
  62.       *    CONVERT BASE-10 -> BASE-6...
  63.             CALL 'CONV-BASE-6' USING WS-EM-HOUR.
  64.             CALL 'CONV-BASE-6' USING WS-EM-MINUTE.
  65.             CALL 'CONV-BASE-6' USING WS-EM-SECOND.
  66.       *    OUTPUT TO CONSOLE
  67.             DISPLAY 'STANDARD TIME: ', WS-STANDARD-TIME.
  68.             DISPLAY 'EMILY TIME:    ', WS-EM-TIME.
  69.             STOP RUN.
  70.        END PROGRAM EMTIME-CONVERTER.
  71.       *
  72.        IDENTIFICATION DIVISION.
  73.        PROGRAM-ID. CONV-BASE-6.
  74.        ENVIRONMENT DIVISION.
  75.        CONFIGURATION SECTION.
  76.        REPOSITORY.
  77.             FUNCTION ALL INTRINSIC.
  78.        DATA DIVISION.
  79.        LOCAL-STORAGE SECTION.
  80.        01   LS-QUO        PIC Z(9) VALUE 1.
  81.        01   LS-REM        PIC Z(9) VALUE 1.
  82.        01   LS-STRING     REDEFINES LS-REM PIC X(9).
  83.        01   LS-RETURN     PIC X(20) VALUE SPACES.
  84.        LINKAGE SECTION.
  85.        01   L-TIME PIC 9(2).
  86.        PROCEDURE DIVISION USING L-TIME.
  87.             PERFORM UNTIL LS-QUO = SPACES
  88.             MOVE 0 TO LS-QUO
  89.             DIVIDE L-TIME BY 6 GIVING LS-QUO REMAINDER LS-REM
  90.       *    BECAUSE WE ARE USING Z, ZEROES TURN TO SPACES. REPLACE IT!
  91.             IF LS-REM = SPACES THEN
  92.                 STRING '0', LS-RETURN INTO LS-RETURN
  93.             ELSE
  94.                 STRING TRIM(LS-STRING),LS-RETURN INTO LS-RETURN
  95.             END-IF
  96.             MOVE LS-QUO TO L-TIME
  97.             END-PERFORM.
  98.             MOVE LS-RETURN(2:) TO LS-RETURN.
  99.             MOVE NUMVAL(LS-RETURN) TO L-TIME.
  100.        END PROGRAM CONV-BASE-6.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement