[Include] Timestamp.inc - Time & date unit conversions
#1

Timestamp.inc

A simple time conversion library, wasn't documented but was there in my github for some time. You are able to convert timestamps to date and vise versa.
Supports time zones (GMT) and leap year.

Functions:
  • Timestamp(year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, hourGMT = 0, minuteGMT = 0);

    Returns a timestamp for the given parameters (year, month, etc.).
    If year/month/day are left as 0, then the function returns current time timestamp.

    Example:
    pawn Код:
    new ts = Timestamp(); // current time

  • ParseTimestamp(timestamp, &year = 0, &month = 0, &day = 0, &hour = 0, &minute = 0, &second = 0, hourGMT = 0, minuteGMT = 0);

    Parses the timestamp into year, month, etc. variables.

    Example:
    pawn Код:
    new day, hour; // we just wanna know the day and hour of timestamp
    ParseTimestamp(ts, .day = day, .hour = hour);

    printf("day = %i, hour = %i", day, hour); 4
    // output: "day = 30, hour = 2"

  • FormatTimestamp(timestamp, const format[], hourGMT = 0, minuteGMT = 0);

    Format the timestamp and return as a string.
    The length of string returned is defined as "MAX_TIMESTAMP_FORMAT_LENGTH" (value=128).
    The available specifiers are:
    Код:
    "%y" - year abbreviated (last 2 chars)
    "%Y" - full year number
    "%m" - month number
    "%b" - month name abbreviated (first 3 chars)
    "%B" - full month name
    "%d" - day
    "%H" - hour (24H clock)
    "%I" - hour (12H clock)
    "%p" - AM or PM (12H clock)
    "%M" - minute
    "%S" - second
    Example:
    pawn Код:
    printf(FormatTimestamp(Timestamp(), "%Y-%m-%d %H:%M:%S"));
    // output: "2019-30-1 2:54:11"

    printf(FormatTimestamp(Timestamp(), "%d %b, %Y"));
    // output: "30 January, 2019"

  • FormatTimeleft(startTimestamp, endTimestamp);

    Return the approximate time left between two timestamps.

    Example:
    pawn Код:
    new now = Timestamp();
    new before = now - ConvertToSeconds(Day, 5); // substract 5 days from current time

    printf("%s ago", FormatTimeleft(before, now));
    // output: "5 days ago"

  • ConvertFromSeconds(TimeUnit:type, seconds);

    Convert seconds into some other unit.
    Available units:
    Код:
    Year,
    Month,
    Day,
    Hour,
    Minute
  • ConvertToSeconds(TimeUnit:type, value);

    Convert any given unit value into seconds.
Download:

https://github.com/Agneese-Saini/SA-.../timestamp.inc
Reply


Messages In This Thread
Timestamp.inc - Time & date unit conversions - by Gammix - 30.01.2019, 07:01
Re: Timestamp.inc - Time & date unit conversions - by Calisthenics - 30.01.2019, 08:43
Re: Timestamp.inc - Time & date unit conversions - by Logic_ - 30.01.2019, 10:24

Forum Jump:


Users browsing this thread: 1 Guest(s)