1
0
Fork 0

- added 'gemini-history-rows';

- moved symbol for function to get a local time object from db to misc package;

- added more wrapper function to local-time library.
This commit is contained in:
cage 2024-11-29 13:50:19 +01:00
parent 5239263f96
commit 06df9318ab
5 changed files with 44 additions and 12 deletions

View File

@ -273,9 +273,6 @@ nil (default T), start a new connection"
(db:maybe-build-all-tables)
(progn ,@body)))
(defun local-time-obj-now ()
(local-time:now))
; db -> application
(defun encode-datetime-string (d &optional (fallback nil))
"Encode a datetime string from db"

View File

@ -874,7 +874,7 @@ to the corresponding id in table +table-account+"
(let* ((last-inserted (last-in-history prompt)))
(when (or (null last-inserted)
(not (string= input (getf last-inserted :input))))
(let* ((now (prepare-for-db (local-time-obj-now)))
(let* ((now (prepare-for-db (misc:local-time-obj-now)))
(insert-query (make-insert :input-history
(:prompt :input :date-added)
(prompt input now))))
@ -921,7 +921,7 @@ than `max-id'"
(defun threshold-time (days-in-the-past)
"Returns a time object `days-in-the-past' days in the past"
(local-time:adjust-timestamp (local-time-obj-now)
(local-time:adjust-timestamp (misc:local-time-obj-now)
(offset :day (- (abs days-in-the-past)))))
(defun purge-by-date-added (table threshold)
@ -1335,7 +1335,7 @@ than (swconf:config-purge-history-days-offset) days in the past"
(assert status-id)
(let ((actual-username (clean-chars username))
(actual-acct (clean-chars account-name))
(now (prepare-for-db (local-time-obj-now))))
(now (prepare-for-db (misc:local-time-obj-now))))
(when (not (mentioned-username->acct actual-username
status-id
:add-mention-prefix nil))
@ -2816,7 +2816,7 @@ account that wrote the status identified by `status-id'"
(:= :timeline timeline))))))
(defmacro with-db-current-timestamp ((timestamp) &body body)
`(let ((,timestamp (prepare-for-db (local-time-obj-now))))
`(let ((,timestamp (prepare-for-db (misc:local-time-obj-now))))
,@body))
(defun add-to-status-ignored (status-id folder timeline)
@ -3587,3 +3587,22 @@ Note: `status-id' must identify at least a row in the database."
(defun strip-folder-prefix (maybe-folder)
(strip-prefix +folder-tag-prefix+ maybe-folder))
(defun gemini-history-rows (days-from days-to prompt)
"Return past data included in ( days-from, days-to]
So if asking for data today and yesterday
(days-from = 1 and days-to = 0), will return the data from today only.
Rows are ordered from the most recent to the oldest."
(let ((actual-days-from (misc:modify-timestamp
(misc:modify-timestamp (misc:time-n-days-ago days-from)
:set :hour 23)
:set :minute 59)))
(let* ((from (prepare-for-db actual-days-from))
(to (prepare-for-db (misc:time-n-days-ago days-to)))
(query (select :*
(from :input-history)
(where (:and (:<= :date-added to)
(:> :date-added from)
(:= :prompt prompt)))
(order-by (:desc :date-added)))))
(fetch-all (query query)))))

View File

@ -123,7 +123,7 @@
:initarg :download-iri
:accessor download-iri)
(start-time
:initform (db-utils:local-time-obj-now)
:initform (misc:local-time-obj-now)
:initarg :start-time
:accessor start-time)
(download-stream
@ -263,7 +263,7 @@
(stream-status stream-status)
(download-iri download-iri)) object
(setf thread (make-thread function))
(setf start-time (db-utils:local-time-obj-now))
(setf start-time (misc:local-time-obj-now))
(setf download-iri (gemini-parser:make-gemini-iri host
path
:scheme scheme

View File

@ -990,8 +990,11 @@ to the array"
(truncate (max 0
(num:safe-parse-number year)))))
(defun local-time-obj-now ()
(local-time:now))
(defun current-year ()
(local-time:timestamp-year (db-utils:local-time-obj-now)))
(local-time:timestamp-year (local-time-obj-now)))
(defun extract-year-from-timestamp (ts)
(local-time:timestamp-year ts))
@ -1003,6 +1006,16 @@ to the array"
(with-output-to-string (stream)
(local-time:format-timestring stream local-time-object :format format-control-list)))
(defun time-n-days-ago (days-ago)
(let ((now (local-time-obj-now)))
(local-time:timestamp- now days-ago :day)))
(defun modify-timestamp (object operation units new-value)
(assert (member operation '(:set :offset)))
(if (eq operation :set)
(local-time:adjust-timestamp! object (:set units new-value))
(local-time:adjust-timestamp! object (:offset units new-value))))
;; threads
(defmacro with-lock-held ((lock) &body body)

View File

@ -265,6 +265,9 @@
:time-daylight-p-of
:time-zone-of
:year->timestamp
:local-time-obj-now
:time-n-days-ago
:modify-timestamp
:current-year
:extract-year-from-timestamp
:format-time
@ -892,7 +895,6 @@
:count-all
:query
:query->sql
:local-time-obj-now
:decode-date-string
:decode-datetime-string
:encode-datetime-string
@ -1218,7 +1220,8 @@
:get-parent-status-row
:has-folder-prefix-p
:add-folder-prefix
:strip-folder-prefix))
:strip-folder-prefix
:gemini-history-rows))
(defpackage :date-formatter
(:use