parent
a199f10078
commit
3a3ac10a32
35
debug.lsp
35
debug.lsp
|
|
@ -1,24 +1,31 @@
|
|||
(define time (get-universal-time))
|
||||
(str-to-date (date-to-str time "%Y-%m-%d %H:%M:%S") "%Y-%m-%d %H:%M:%S")
|
||||
(defun a (aa) (print aa))
|
||||
(a 1 2)
|
||||
|
||||
;; (define csv_date (str-to-date "01/01/2021" "%m/%d/%Y"))
|
||||
;; (date-to-str 3141583200 "%m/%d/%Y")
|
||||
|
||||
|
||||
(define create_tbl_sql "create table prices (datetime integer, symbol varchar(8), prev_close float, open float, price float, change float, change_prct varchar(16))")
|
||||
(define insert_sql "insert into prices (datetime, symbol, prev_close, open, price, change, change_prct) values (1626979443, 'MPC', 54.08, 53.82, 53.63, -0.832101, '-0.83 %')")
|
||||
(define select_sql "select to_string(datetime, '%d.%m.%Y %H:%M:%S'), symbol, prev_close, open, price, change, change_prct from prices")
|
||||
;; (define time (get-universal-time))
|
||||
;; (str-to-date (date-to-str time "%Y-%m-%d %H:%M:%S") "%Y-%m-%d %H:%M:%S")
|
||||
|
||||
|
||||
(print (usql create_tbl_sql))
|
||||
(print (usql insert_sql))
|
||||
(print (usql select_sql))
|
||||
;; (define create_tbl_sql "create table prices (datetime integer, symbol varchar(8), prev_close float, open float, price float, change float, change_prct varchar(16))")
|
||||
;; (define insert_sql "insert into prices (datetime, symbol, prev_close, open, price, change, change_prct) values (1626979443, 'MPC', 54.08, 53.82, 53.63, -0.832101, '-0.83 %')")
|
||||
;; (define select_sql "select to_string(datetime, '%d.%m.%Y %H:%M:%S'), symbol, prev_close, open, price, change, change_prct from prices")
|
||||
|
||||
(print (usql "select to_string(datetime, '%d.%m.%Y %H:%M:%S'), symbol, prev_close, open, price, change, change_prct from prices"))
|
||||
|
||||
(define var "promena var")
|
||||
(define var2 "promena var2")
|
||||
(print var)
|
||||
(print var2)
|
||||
;; (print (usql create_tbl_sql))
|
||||
;; (print (usql insert_sql))
|
||||
;; (print (usql select_sql))
|
||||
|
||||
(print (+ "select min(adjClose), max(adjClose) from history_prices where symbol = '" var "'"))
|
||||
;; (print (usql "select to_string(datetime, '%d.%m.%Y %H:%M:%S'), symbol, prev_close, open, price, change, change_prct from prices"))
|
||||
|
||||
;; (define var "promena var")
|
||||
;; (define var2 "promena var2")
|
||||
;; (print var)
|
||||
;; (print var2)
|
||||
|
||||
;; (print (+ "select min(adjClose), max(adjClose) from history_prices where symbol = '" var "'"))
|
||||
|
||||
;; (print (usql "create table data (ticker varchar(8), price float null)"))
|
||||
;; (usql "load data from '/Users/vaclavt/Library/Mobile Documents/com~apple~CloudDocs/Development/usql/data.csv')")
|
||||
|
|
|
|||
12
ml_date.cpp
12
ml_date.cpp
|
|
@ -23,8 +23,7 @@ std::string date_to_string(const long datetime, const std::string format) {
|
|||
}
|
||||
|
||||
time_t time_to_epoch ( const struct tm *ltm, int utcdiff ) {
|
||||
// const int mon_days [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
const int mon_days [] = {31, 31+28, 31+28+31,
|
||||
const int mon_days [] = {0, 31, 31+28, 31+28+31,
|
||||
31+28+31+30, 31+28+31+30+31, 31+28+31+30+31+30,
|
||||
31+28+31+30+31+30+31, 31+28+31+30+31+30+31+31, 31+28+31+30+31+30+31+31+30,
|
||||
31+28+31+30+31+30+31+31+30+31, 31+28+31+30+31+30+31+31+30+31+30, 31+28+31+30+31+30+31+31+30+31+30+31};
|
||||
|
|
@ -38,8 +37,9 @@ time_t time_to_epoch ( const struct tm *ltm, int utcdiff ) {
|
|||
//leaps -= ( (i/4)*3 + i%4 );
|
||||
|
||||
// tdays = 0;
|
||||
// const int mon_days [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
// for (i=0; i < ltm->tm_mon; i++) tdays += mon_days[i];
|
||||
tdays = mon_days[ltm->tm_mon-1];
|
||||
tdays = mon_days[ltm->tm_mon];
|
||||
|
||||
tdays += ltm->tm_mday-1; // days of month passed.
|
||||
tdays = tdays + (tyears * 365) + leaps;
|
||||
|
|
@ -67,10 +67,12 @@ long string_to_date(const std::string &datestr, const std::string &format) {
|
|||
timeinfo->tm_min = tm.tm_min;
|
||||
timeinfo->tm_sec = tm.tm_sec;
|
||||
|
||||
return time_to_epoch(timeinfo, -1 * timeinfo->tm_gmtoff);
|
||||
int offset = -1 * timeinfo->tm_gmtoff; // for local time
|
||||
//int offset = 0;
|
||||
return time_to_epoch(timeinfo, offset);
|
||||
}
|
||||
|
||||
throw std::runtime_error("string_to_date invalid date string or format");
|
||||
throw std::runtime_error("invalid date string or format (" + datestr + ", " + format + ")" );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -101,19 +101,19 @@
|
|||
|
||||
|
||||
; it is in local time
|
||||
(ut::define-test "result of (str-to-date \"01.01.1970\" \"%d.%m.%Y\")" '(ut::assert-equal -7200 (str-to-date "01.01.1970" "%d.%m.%Y")))
|
||||
(ut::define-test "result of (date-add (str-to-date \"01.01.1970\" \"%d.%m.%Y\") 1 \"day\")" '(ut::assert-equal 79200 (date-add (str-to-date "01.01.1970" "%d.%m.%Y") 1 "day")))
|
||||
(ut::define-test "result of (str-to-date \"01.01.1970\" \"%d.%m.%Y\")" '(ut::assert-equal 0 (str-to-date "01.01.1970" "%d.%m.%Y")))
|
||||
(ut::define-test "result of (date-add (str-to-date \"01.01.1970\" \"%d.%m.%Y\") 1 \"day\")" '(ut::assert-equal 86400 (date-add (str-to-date "01.01.1970" "%d.%m.%Y") 1 "day")))
|
||||
|
||||
(ut::define-test "result of (start-of-day)" '(ut::assert-equal 1620856800 (start-of-day (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
(ut::define-test "result of (end-of-day)" '(ut::assert-equal 1620943199 (end-of-day (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
(ut::define-test "result of (start-of-month)" '(ut::assert-equal 1619820000 (start-of-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
(ut::define-test "result of (end-of-month)" '(ut::assert-equal 1622498399 (end-of-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
(ut::define-test "result of (start-of-next-month)" '(ut::assert-equal 1622498400 (start-of-next-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
(ut::define-test "result of (end-of-next-month)" '(ut::assert-equal 1625176799 (end-of-next-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
(ut::define-test "result of (start-of-prev-month)" '(ut::assert-equal 1617228000 (start-of-prev-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
(ut::define-test "result of (end-of-prev-month)" '(ut::assert-equal 1619906399 (end-of-prev-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
(ut::define-test "result of (start-of-year)" '(ut::assert-equal 1609452000 (start-of-year (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
(ut::define-test "result of (end-of-year)" '(ut::assert-equal 1640987999 (end-of-year (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
(ut::define-test "result of (start-of-day)" '(ut::assert-equal 1620864000 (start-of-day (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
(ut::define-test "result of (end-of-day)" '(ut::assert-equal 1620950399 (end-of-day (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
(ut::define-test "result of (start-of-month)" '(ut::assert-equal 1619827200 (start-of-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
(ut::define-test "result of (end-of-month)" '(ut::assert-equal 1622505599 (end-of-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
(ut::define-test "result of (start-of-next-month)" '(ut::assert-equal 1622505600 (start-of-next-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
(ut::define-test "result of (end-of-next-month)" '(ut::assert-equal 1625097599 (end-of-next-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
(ut::define-test "result of (start-of-prev-month)" '(ut::assert-equal 1617235200 (start-of-prev-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
(ut::define-test "result of (end-of-prev-month)" '(ut::assert-equal 1619827199 (end-of-prev-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
(ut::define-test "result of (start-of-year)" '(ut::assert-equal 1609459200 (start-of-year (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
(ut::define-test "result of (end-of-year)" '(ut::assert-equal 1640995199 (end-of-year (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S"))))
|
||||
|
||||
(ut::define-test "(read-file-lines \"/tmp/f.txt\" counter)" '(ut::assert-equal 3 (read-file-lines "/tmp/f.txt" counter)))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue