8000 Move timeofday() implementation out of nabstime.c. · postgres/postgres@86896be · GitHub
[go: up one dir, main page]

Skip to content
  • Commit 86896be

    Browse files
    committed
    Move timeofday() implementation out of nabstime.c.
    nabstime.c is about to be removed, but timeofday() isn't related to the rest of the functionality therein, and some find it useful. Move to timestamp.c. Discussion: https://postgr.es/m/20181009192237.34wjp3nmw7oynmmr@alap3.anarazel.de https://postgr.es/m/20180928223240.kgwc4czzzekrpsid%40alap3.anarazel.de
    1 parent e9edc1b commit 86896be

    File tree

    2 files changed

    +20
    -29
    lines changed

    2 files changed

    +20
    -29
    lines changed

    src/backend/utils/adt/nabstime.c

    Lines changed: 0 additions & 29 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1539,32 +1539,3 @@ parsetinterval(char *i_string,
    15391539
    "tinterval", i_string)));
    15401540
    *i_start = *i_end = INVALID_ABSTIME; /* keep compiler quiet */
    15411541
    }
    1542-
    1543-
    1544-
    /*****************************************************************************
    1545-
    *
    1546-
    *****************************************************************************/
    1547-
    1548-
    /*
    1549-
    * timeofday -
    1550-
    * returns the current time as a text. similar to timenow() but returns
    1551-
    * seconds with more precision (up to microsecs). (I need this to compare
    1552-
    * the Wisconsin benchmark with Illustra whose TimeNow() shows current
    1553-
    * time with precision up to microsecs.) - ay 3/95
    1554-
    */
    1555-
    Datum
    1556-
    timeofday(PG_FUNCTION_ARGS)
    1557-
    {
    1558-
    struct timeval tp;
    1559-
    char templ[128];
    1560-
    char buf[128];
    1561-
    pg_time_t tt;
    1562-
    1563-
    gettimeofday(&tp, NULL);
    1564-
    tt = (pg_time_t) tp.tv_sec;
    1565-
    pg_strftime(templ, sizeof(templ), "%a %b %d %H:%M:%S.%%06d %Y %Z",
    1566-
    pg_localtime(&tt, session_timezone));
    1567-
    snprintf(buf, sizeof(buf), templ, tp.tv_usec);
    1568-
    1569-
    PG_RETURN_TEXT_P(cstring_to_text(buf));
    1570-
    }

    src/backend/utils/adt/timestamp.c

    Lines changed: 20 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1609,6 +1609,26 @@ GetSQLLocalTimestamp(int32 typmod)
    16091609
    return ts;
    16101610
    }
    16111611

    1612+
    /*
    1613+
    * timeofday(*) -- returns the current time as a text.
    1614+
    */
    1615+
    Datum
    1616+
    timeofday(PG_FUNCTION_ARGS)
    1617+
    {
    1618+
    struct timeval tp;
    1619+
    char templ[128];
    1620+
    char buf[128];
    1621+
    pg_time_t tt;
    1622+
    1623+
    gettimeofday(&tp, NULL);
    1624+
    tt = (pg_time_t) tp.tv_sec;
    1625+
    pg_strftime(templ, sizeof(templ), "%a %b %d %H:%M:%S.%%06d %Y %Z",
    1626+
    pg_localtime(&tt, session_timezone));
    1627+
    snprintf(buf, sizeof(buf), templ, tp.tv_usec);
    1628+
    1629+
    PG_RETURN_TEXT_P(cstring_to_text(buf));
    1630+
    }
    1631+
    16121632
    /*
    16131633
    * TimestampDifference -- convert the difference between two timestamps
    16141634
    * into integer seconds and microseconds

    0 commit comments

    Comments
     (0)
    0