Time
Access to the internal computer clock.
#Header
#include <osbs/btime.h>
#Functions
| uint64_t | btime_now (void) |
| void | btime_date (...) |
| uint64_t | btime_to_micro (...) |
| void | btime_to_date (...) |
| week_day_t | btime_first_wday (void) |
| void | btime_month_name (...) |
| void | btime_wday_name (...) |
The operating system measures the passage of time using an internal clock, typically implemented by a counter of the ticks that have passed since an initial moment called epoch. In Unix-like systems this counter represents the number of seconds elapsed since January 1, 1970 UTC. However, in Windows it represents the number of 100 nanosecond intervals since January 1, 1601 coinciding with the beginning of the Gregorian calendar. In NAppGUI these values have been unified to work with Unix Epoch on all platforms.
- Use btime_now to get the number of micro-seconds elapsed since January 1, 1970 UTC.
- Use btime_date to get the system date.
- Use btime_to_micro and btime_to_date to convert dates to Unix Time and vice versa.
The difference between two instants will give us the time elapsed during the execution of a task.
1 2 3 4 5 6 7 |
uint64_t ed, st = btime_now(); // Do something... ... ed = btime_now(); bstd_printf("Total elapsed micro-seconds: %lu\n", ed - st); |
Some calendar conventions depend on the user's regional settings, such as the day the week starts on or the names of months and days. For example, in Spain the week starts on Monday and in the United States on Sunday. These values are obtained directly from the operating system, respecting any customizations made by the user.
- Use btime_first_wday to get the first day of the week.
- Use btime_month_name to get the name of a month.
- Use btime_wday_name to get the abbreviated name of a weekday.
1 2 3 4 5 6 |
char_t month[64]; char_t wday[16]; week_day_t first = btime_first_wday(); btime_month_name(ekNOVEMBER, month, sizeof(month)); btime_wday_name(first, wday, sizeof(wday)); bstd_printf("%s, week starts on: %s\n", month, wday); |
#btime_now ()
Gets the number of micro-seconds elapsed since January 1, 1970 until this precise moment. Use the difference between instants to know the time consumed by a process.
uint64_t btime_now(void);
Return
The number of micro-seconds elapsed, that is, the number of intervals of 1/1000000 seconds.
Remarks
The initial instant is January 1, 1970 in Unix/Linux systems and January 1, 1601 in Windows since it is the first year of the Gregorian cycle in which Windows NT was activated. This function equates both starts, always returning the Unix time.
#btime_date ()
Gets the current system date.
void btime_date(Date *date);
| date | Current date. |
#btime_to_micro ()
Convert a date to Unix Time.
uint64_t btime_to_micro(const Date *date);
| date | The date to convert. |
Return
The number of micro-seconds since January 1, 1970 UTC.
#btime_to_date ()
Transform Unix Time into a date.
void btime_to_date(const uint64_t micro, Date *date);
| micro | Number of micro-seconds since January 1, 1970 UTC. |
| date | Result date. |
#btime_first_wday ()
Gets the first day of the week according to the user's regional settings.
week_day_t btime_first_wday(void);
Return
The first day of the week.
#btime_month_name ()
Gets the name of a month according to the user's regional settings.
void btime_month_name(const month_t month, char_t *name, const uint32_t size);
| month | The month. |
| name | Buffer where the name will be written (UTF-8). |
| size | Buffer size in bytes. |
Remarks
The full name is returned in its standalone form, as it appears in a calendar header (e.g. "noviembre" and not "de noviembre" in Spanish). Capitalization depends on the language.
#btime_wday_name ()
Gets the abbreviated name of a weekday according to the user's regional settings.
void btime_wday_name(const week_day_t wday, char_t *name, const uint32_t size);
| wday | The weekday. |
| name | Buffer where the name will be written (UTF-8). |
| size | Buffer size in bytes. |
Remarks
The shortest abbreviation provided by the operating system is returned, so its length may vary between platforms (one, two or three letters).


