<commit_before>(in-package :local-time)

(export 'set-local-time-cl-postgres-readers :local-time)

;; Postgresql days are measured from 01-01-2000, whereas local-time
;; uses 01-03-2000. We expect the database server to be in the UTC timezone.
(defconstant +postgres-day-offset-to-local-time+ -60)

(defun set-local-time-cl-postgres-readers (&optional (table cl-postgres:*sql-readtable*))
  (flet ((timestamp-reader (usecs)
           (multiple-value-bind (days usecs)
               (floor usecs +usecs-per-day+)
             (multiple-value-bind (secs usecs)
                 (floor usecs 1000000)
               (local-time:make-timestamp :nsec (* usecs 1000)
                                          :sec secs
                                          :day (+ days +postgres-day-offset-to-local-time+)
                                          :timezone local-time:+utc-zone+)))))
    (cl-postgres:set-sql-datetime-readers
     :table table
     :date
     (lambda (days)
       (local-time:make-timestamp
        :nsec 0 :sec 0 :day (+ days +postgres-day-offset-to-local-time+)
        :timezone local-time:+utc-zone+))
     :timestamp #'timestamp-reader
     :timestamp-with-timezone #'timestamp-reader
     :interval
     (lambda (months days usecs)
       (declare (ignore months days usecs))
       (error "Intervals are not yet supported"))
     :time
     (lambda (usecs)
       (multiple-value-bind (days usecs)
           (floor usecs +usecs-per-day+)
         (assert (= days 0))
         (multiple-value-bind (secs usecs)
             (floor usecs 1000000)
           (local-time:make-timestamp
            :nsec (* usecs 1000)
            :sec secs
            :day 0
            :timezone local-time:+utc-zone+)))))))

(defmethod cl-postgres:to-sql-string ((arg local-time:timestamp))
  (local-time:format-rfc3339-timestring nil arg :timezone +utc-zone+))<commit_msg> cl-postgres integration updated to new local-time API<commit_after>(in-package :local-time)

(export 'set-local-time-cl-postgres-readers :local-time)

;; Postgresql days are measured from 2000-01-01, whereas local-time
;; uses 2000-03-01. We expect the database server to be in the UTC timezone.
(defconstant +postgres-day-offset-to-local-time+ -60)

(defun set-local-time-cl-postgres-readers (&optional (table cl-postgres:*sql-readtable*))
  (flet ((timestamp-reader (usecs)
           (multiple-value-bind (days usecs)
               (floor usecs +usecs-per-day+)
             (multiple-value-bind (secs usecs)
                 (floor usecs 1000000)
               (local-time:make-timestamp :nsec (* usecs 1000)
                                          :sec secs
                                          :day (+ days +postgres-day-offset-to-local-time+))))))
    (cl-postgres:set-sql-datetime-readers
     :table table
     :date (lambda (days)
             (local-time:make-timestamp
              :nsec 0 :sec 0
              :day (+ days +postgres-day-offset-to-local-time+)))
     :timestamp #'timestamp-reader
     :timestamp-with-timezone #'timestamp-reader
     :interval
     (lambda (months days usecs)
       (declare (ignore months days usecs))
       (error "Intervals are not yet supported"))
     :time
     (lambda (usecs)
       (multiple-value-bind (days usecs)
           (floor usecs +usecs-per-day+)
         (assert (= days 0))
         (multiple-value-bind (secs usecs)
             (floor usecs 1000000)
           (local-time:make-timestamp
            :nsec (* usecs 1000)
            :sec secs
            :day 0)))))))

(defmethod cl-postgres:to-sql-string ((arg local-time:timestamp))
  (local-time:format-rfc3339-timestring arg))
{'fraction_non_alphanumeric': 0.1271581255138394, 'fraction_numerical': 0.026308577692518497, 'mean_word_length': 2.074978938500421, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5878620', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1127, 'n_words': 263}