1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-09-20 05:34:47 +00:00

Move more date/time functions

This commit is contained in:
Matthew Kilgore 2024-02-13 01:07:07 -05:00
parent b9a4bec188
commit fb16492ac8
4 changed files with 132 additions and 125 deletions

View file

@ -17519,127 +17519,6 @@ void sub_graphics_put(float x1f, float y1f, void *element, int32 option, uint32
*/ */
} }
void sub_date(qbs *date) {
if (is_error_pending())
return;
return; // stub
}
qbs *func_date() {
// mm-dd-yyyy
// 0123456789
static time_t qb64_tm_val;
static tm *qb64_tm;
// struct tm {
// int tm_sec; /* seconds after the minute - [0,59] */
// int tm_min; /* minutes after the hour - [0,59] */
// int tm_hour; /* hours since midnight - [0,23] */
// int tm_mday; /* day of the month - [1,31] */
// int tm_mon; /* months since January - [0,11] */
// int tm_year; /* years since 1900 */
// int tm_wday; /* days since Sunday - [0,6] */
// int tm_yday; /* days since January 1 - [0,365] */
// int tm_isdst; /* daylight savings time flag */
// };
static int32 x, x2, i;
static qbs *str;
str = qbs_new(10, 1);
str->chr[2] = 45;
str->chr[5] = 45; //-
time(&qb64_tm_val);
if (qb64_tm_val == -1) {
error(5);
str->len = 0;
return str;
}
qb64_tm = localtime(&qb64_tm_val);
if (qb64_tm == NULL) {
error(5);
str->len = 0;
return str;
}
x = qb64_tm->tm_mon;
x++;
i = 0;
str->chr[i] = x / 10 + 48;
str->chr[i + 1] = x % 10 + 48;
x = qb64_tm->tm_mday;
i = 3;
str->chr[i] = x / 10 + 48;
str->chr[i + 1] = x % 10 + 48;
x = qb64_tm->tm_year;
x += 1900;
i = 6;
x2 = x / 1000;
x = x - x2 * 1000;
str->chr[i] = x2 + 48;
i++;
x2 = x / 100;
x = x - x2 * 100;
str->chr[i] = x2 + 48;
i++;
x2 = x / 10;
x = x - x2 * 10;
str->chr[i] = x2 + 48;
i++;
str->chr[i] = x + 48;
return str;
}
void sub_time(qbs *str) {
if (is_error_pending())
return;
return; // stub
}
qbs *func_time() {
// 23:59:59 (hh:mm:ss)
// 01234567
static time_t qb64_tm_val;
static tm *qb64_tm;
// struct tm {
// int tm_sec; /* seconds after the minute - [0,59] */
// int tm_min; /* minutes after the hour - [0,59] */
// int tm_hour; /* hours since midnight - [0,23] */
// int tm_mday; /* day of the month - [1,31] */
// int tm_mon; /* months since January - [0,11] */
// int tm_year; /* years since 1900 */
// int tm_wday; /* days since Sunday - [0,6] */
// int tm_yday; /* days since January 1 - [0,365] */
// int tm_isdst; /* daylight savings time flag */
// };
static int32 x, x2, i;
static qbs *str;
str = qbs_new(8, 1);
str->chr[2] = 58;
str->chr[5] = 58; //:
time(&qb64_tm_val);
if (qb64_tm_val == -1) {
error(5);
str->len = 0;
return str;
}
qb64_tm = localtime(&qb64_tm_val);
if (qb64_tm == NULL) {
error(5);
str->len = 0;
return str;
}
x = qb64_tm->tm_hour;
i = 0;
str->chr[i] = x / 10 + 48;
str->chr[i + 1] = x % 10 + 48;
x = qb64_tm->tm_min;
i = 3;
str->chr[i] = x / 10 + 48;
str->chr[i + 1] = x % 10 + 48;
x = qb64_tm->tm_sec;
i = 6;
str->chr[i] = x / 10 + 48;
str->chr[i + 1] = x % 10 + 48;
return str;
}
int32 func_csrlin() { int32 func_csrlin() {
#ifdef QB64_WINDOWS // Windows console CSRLIN support #ifdef QB64_WINDOWS // Windows console CSRLIN support
if (write_page->console) { if (write_page->console) {

View file

@ -1,6 +1,9 @@
#ifndef INCLUDE_LIBQB_DATETIME_H #ifndef INCLUDE_LIBQB_DATETIME_H
#define INCLUDE_LIBQB_DATETIME_H #define INCLUDE_LIBQB_DATETIME_H
#include <stdint.h>
#include "qbs.h"
int64_t GetTicks(); int64_t GetTicks();
double func_timer(double accuracy, int32_t passed); double func_timer(double accuracy, int32_t passed);
@ -12,4 +15,10 @@ void sub__limit(double fps);
void Sleep(uint32_t milliseconds); void Sleep(uint32_t milliseconds);
#endif #endif
qbs *func_time();
void sub_time(qbs *str);
qbs *func_date();
void sub_date(qbs *date);
#endif #endif

View file

@ -10,6 +10,8 @@
#include "rounding.h" #include "rounding.h"
#include "event.h" #include "event.h"
#include "error_handle.h"
#include "qbs.h"
#include "datetime.h" #include "datetime.h"
#ifdef QB64_MACOSX #ifdef QB64_MACOSX
@ -194,3 +196,124 @@ recalculate:
prev = now; prev = now;
} }
void sub_date(qbs *date) {
if (is_error_pending())
return;
return; // stub
}
qbs *func_date() {
// mm-dd-yyyy
// 0123456789
static time_t qb64_tm_val;
static tm *qb64_tm;
// struct tm {
// int tm_sec; /* seconds after the minute - [0,59] */
// int tm_min; /* minutes after the hour - [0,59] */
// int tm_hour; /* hours since midnight - [0,23] */
// int tm_mday; /* day of the month - [1,31] */
// int tm_mon; /* months since January - [0,11] */
// int tm_year; /* years since 1900 */
// int tm_wday; /* days since Sunday - [0,6] */
// int tm_yday; /* days since January 1 - [0,365] */
// int tm_isdst; /* daylight savings time flag */
// };
static int32_t x, x2, i;
static qbs *str;
str = qbs_new(10, 1);
str->chr[2] = 45;
str->chr[5] = 45; //-
time(&qb64_tm_val);
if (qb64_tm_val == -1) {
error(5);
str->len = 0;
return str;
}
qb64_tm = localtime(&qb64_tm_val);
if (qb64_tm == NULL) {
error(5);
str->len = 0;
return str;
}
x = qb64_tm->tm_mon;
x++;
i = 0;
str->chr[i] = x / 10 + 48;
str->chr[i + 1] = x % 10 + 48;
x = qb64_tm->tm_mday;
i = 3;
str->chr[i] = x / 10 + 48;
str->chr[i + 1] = x % 10 + 48;
x = qb64_tm->tm_year;
x += 1900;
i = 6;
x2 = x / 1000;
x = x - x2 * 1000;
str->chr[i] = x2 + 48;
i++;
x2 = x / 100;
x = x - x2 * 100;
str->chr[i] = x2 + 48;
i++;
x2 = x / 10;
x = x - x2 * 10;
str->chr[i] = x2 + 48;
i++;
str->chr[i] = x + 48;
return str;
}
void sub_time(qbs *str) {
if (is_error_pending())
return;
return; // stub
}
qbs *func_time() {
// 23:59:59 (hh:mm:ss)
// 01234567
static time_t qb64_tm_val;
static tm *qb64_tm;
// struct tm {
// int tm_sec; /* seconds after the minute - [0,59] */
// int tm_min; /* minutes after the hour - [0,59] */
// int tm_hour; /* hours since midnight - [0,23] */
// int tm_mday; /* day of the month - [1,31] */
// int tm_mon; /* months since January - [0,11] */
// int tm_year; /* years since 1900 */
// int tm_wday; /* days since Sunday - [0,6] */
// int tm_yday; /* days since January 1 - [0,365] */
// int tm_isdst; /* daylight savings time flag */
// };
static int32_t x, x2, i;
static qbs *str;
str = qbs_new(8, 1);
str->chr[2] = 58;
str->chr[5] = 58; //:
time(&qb64_tm_val);
if (qb64_tm_val == -1) {
error(5);
str->len = 0;
return str;
}
qb64_tm = localtime(&qb64_tm_val);
if (qb64_tm == NULL) {
error(5);
str->len = 0;
return str;
}
x = qb64_tm->tm_hour;
i = 0;
str->chr[i] = x / 10 + 48;
str->chr[i + 1] = x % 10 + 48;
x = qb64_tm->tm_min;
i = 3;
str->chr[i] = x / 10 + 48;
str->chr[i + 1] = x % 10 + 48;
x = qb64_tm->tm_sec;
i = 6;
str->chr[i] = x / 10 + 48;
str->chr[i + 1] = x % 10 + 48;
return str;
}

View file

@ -370,10 +370,6 @@ extern void sub_graphics_get(float x1f, float y1f, float x2f, float y2f,
void *element, uint32 mask, int32 passed); void *element, uint32 mask, int32 passed);
extern void sub_graphics_put(float x1f, float y1f, void *element, int32 option, extern void sub_graphics_put(float x1f, float y1f, void *element, int32 option,
uint32 mask, int32 passed); uint32 mask, int32 passed);
extern void sub_date(qbs *date);
extern qbs *func_date();
extern void sub_time(qbs *str);
extern qbs *func_time();
extern int32 func_csrlin(); extern int32 func_csrlin();
extern int32 func_pos(int32 ignore); extern int32 func_pos(int32 ignore);
extern double func_log(double value); extern double func_log(double value);