#dev | Logs for 2024-03-02
  « return
[00:46:46] -!- requerdanos has quit [Quit: Offline for hardware maintenance]
[02:07:05] -!- requerdanos [requerdanos!~requerdan@Soylent/Staff/Editor/requerdanos] has joined #dev
[19:21:41] <Bytram> Called program:
[19:21:48] <Bytram> .
[19:22:21] <Bytram> # date_diff - given two unix epochs, calculates years, months, days, etc between them.
[19:22:21] <Bytram> # Modification History:
[19:22:21] <Bytram> #   20170204a Marty Brookes  Original Version
[19:22:21] <Bytram> ###############################################################################
[19:22:21] <Bytram> {
[19:22:22] <Bytram>    t1 = $1;
[19:22:24] <Bytram>    t2 = $2;
[19:22:26] <Bytram>    # Ensure that t1 contains the smaller of the time stamps, and t2 the larger:
[19:22:28] <Bytram>    if (t1 > t2) {
[19:22:32] <Bytram>       x = t1;
[19:22:34] <Bytram>       t1 = t2;
[19:22:36] <Bytram>       t2 = x;
[19:22:38] <Bytram>    }  # if
[19:22:40] <Bytram>    print t1, t2;
[19:22:42] <Bytram>    # Initialize the results:
[19:22:44] <Bytram>    delta_years   = 0;
[19:22:46] <Bytram>    delta_months  = 0;
[19:22:48] <Bytram>    delta_days    = 0;
[19:22:50] <Bytram>    delta_hours   = 0;
[19:22:52] <Bytram>    delta_minutes = 0;
[19:22:54] <Bytram>    delta_seconds = 0;
[19:22:56] <Bytram>    start_years   = strftime("%Y", t1);
[19:22:58] <Bytram>    start_months  = strftime("%m", t1);
[19:23:02] <Bytram>    start_days    = strftime("%d", t1);
[19:23:04] <Bytram>    start_hours   = strftime("%H", t1);
[19:23:06] <Bytram>    start_minutes = strftime("%M", t1);
[19:23:08] <Bytram>    start_seconds = strftime("%S", t1);
[19:23:10] <Bytram>    print start_years, start_months, start_days, start_hours, start_minutes, start_seconds;
[19:23:12] <Bytram>    # Increment the number of delta_years until we get a date later than the end_date, then subtract 1:
[19:23:14] <Bytram>    done = false;
[19:23:16] <Bytram>    for (delta_years=1; done==FALSE; delta_years++) {
[19:23:18] <Bytram>       test_years = sprintf("%4d", start_years + delta_years);
[19:23:20] <Bytram>       # IMPLEMENTATION IS NOT COMPLETE - HARD-CODE AN ABORT:
[19:23:22] <Bytram>       done = TRUE;
[19:23:24] <Bytram>    }
[19:23:26] <Bytram> }
[19:23:28] <Bytram> .
[19:23:32] <Bytram> This is the calling program:
[19:23:34] <Bytram> .
[19:25:49] <Bytram> (I'm not certain that this will work)
[19:25:51] <Bytram> .
[19:26:03] <Bytram> @IF "%echo%"==""  SET echo=OFF
[19:26:03] <Bytram> @ECHO %echo%
[19:26:03] <Bytram> GOTO Top
[19:26:03] <Bytram> :: date_diff - given two unix epochs, calculates years, months, days, etc between them.
[19:26:03] <Bytram> :: Modification History:
[19:26:04] <Bytram> ::   20170204a Marty Brookes  Original Version
[19:26:06] <Bytram> :Top
[19:26:08] <Bytram> IF NOT "%~1"=="--version"  GOTO VersionNo
[19:26:10] <Bytram>    ECHO date_diff - Version 1.00
[19:26:12] <Bytram>    GOTO End
[19:26:14] <Bytram> :VersionNo
[19:26:16] <Bytram> :: See if they need help:
[19:26:18] <Bytram> SET NeedHelp=
[19:26:20] <Bytram> IF     "%~1"=="/?"     SET NeedHelp=Y
[19:26:22] <Bytram> IF     "%~1"=="-?"     SET NeedHelp=Y
[19:26:24] <Bytram> IF     "%~1"=="-h"     SET NeedHelp=Y
[19:26:26] <Bytram> IF     "%~1"=="--help" SET NeedHelp=Y
[19:26:28] <Bytram> IF     "%~2"==""       SET NeedHelp=Y
[19:26:32] <Bytram> IF NOT "%~3"==""       SET NeedHelp=Y
[19:26:34] <Bytram> IF "%NeedHelp%"=="Y"  GOTO Usage
[19:26:36] <Bytram>    :: Get the two date/time stamps:
[19:26:38] <Bytram>    SET date_diff_t1=%~1
[19:26:40] <Bytram>    SET date_diff_t2=%~2
[19:26:42] <Bytram>    :: Allow debugging to leave things behind:
[19:26:44] <Bytram>    IF "%set%"==""   SET set=SET
[19:26:46] <Bytram>    IF "%del%"==""   SET del=DEL
[19:26:48] <Bytram>    :: Allow conditional execution:
[19:26:50] <Bytram>    IF "%call%"==""  SET call=CALL
[19:26:52] <Bytram>    :: Make sure we can access our utilities:
[19:26:54] <Bytram>    IF "%util%"==""        CALL util
[19:26:56] <Bytram>    IF "%UnxUtils%"==""    CALL UnxUtils
[19:26:58] <Bytram>    :: Make sure there is a place to put temporary files:
[19:27:02] <Bytram>    IF "%tmpdir%"==""    CALL tmpdir
[19:27:04] <Bytram>    :: Our AWK script must be in the same dir as this batch program; find it:
[19:27:06] <Bytram>    SET date_diff_whereami=%~dsp0
[19:27:08] <Bytram>    :: Invoke the AWK script which does the calculations:
[19:27:10] <Bytram>    ECHO %date_diff_t1% %date_diff_t2% | gawk -f %date_diff_whereami%\date_diff.awk
[19:27:12] <Bytram>    :: Cleanup:
[19:27:14] <Bytram>    %set% date_diff_t1=
[19:27:16] <Bytram>    %set% date_diff_t2=
[19:27:18] <Bytram>    %set% date_diff_whereami=
[19:27:20] <Bytram> GOTO End
[19:27:22] <Bytram> :Usage
[19:27:24] <Bytram>    SET NeedHelp=
[19:27:26] <Bytram>    ECHO   given two unix epochs, calculates years, months, days, etc between them
[19:27:28] <Bytram>    ECHO.
[19:27:32] <Bytram>    ECHO USAGE:
[19:27:34] <Bytram>    ECHO   date_diff [--version][/?][t1 t2]
[19:27:36] <Bytram>    ECHO.
[19:27:38] <Bytram>    ECHO EXAMPLES:
[19:27:40] <Bytram>    ECHO   date_diff --version        Displays program version and exits
[19:27:42] <Bytram>    ECHO.
[19:27:44] <Bytram>    ECHO   date_diff /?               Generates this help message
[19:27:46] <Bytram>    ECHO.
[19:27:48] <Bytram>    ECHO   CALL mktime --quiet "1993 08 29 00 00 01 -1"
[19:27:50] <Bytram>    ECHO   SET dd_t1=%%mktime%%
[19:27:52] <Bytram>    ECHO   CALL mktime --quiet "2017 02 04 10 55 05 -1"
[19:27:54] <Bytram>    ECHO   SET dd_t2=%%mktime%%
[19:27:56] <Bytram>    ECHO.
[19:27:58] <Bytram>    ECHO   date_diff %%dd_t1%% %%dd_t2%%
[19:28:02] <Bytram>    ECHO                              Calculates the number of years, months, .. seconds
[19:28:04] <Bytram>    ECHO                              between these two Unix epoch time stamps and displays
[19:28:06] <Bytram>    ECHO                              the results on STDOUT; 
[19:28:08] <Bytram>    ECHO
[19:28:10] <Bytram>    ECHO   CALL mktime --quiet "1993 08 29 00 00 01 -1"
[19:28:12] <Bytram>    ECHO   CALL systime
[19:28:14] <Bytram>    ECHO   date_diff %%mktime%% %%systime%%
[19:28:16] <Bytram>    ECHO                              Same, but calculates and displays the duration
[19:28:18] <Bytram>    ECHO                              between then and now
[19:28:20] <Bytram>    ECHO.
[19:28:22] <Bytram> :End
[19:28:24] <Bytram> .
[19:28:26] <Bytram> END
[19:28:45] <Bytram> Note: There were MANY blank lines (that do not appear here) that GREATLY improved readability of BOTH programs!
[19:31:37] -!- janrinok [janrinok!~janrinok@0::1] has joined #dev
[19:46:30] * Bytram waves!