Compare commits

..

2 Commits

Author SHA1 Message Date
Magnus Åhall
d89d63803f Bumped to v24 2024-03-30 09:57:25 +01:00
Magnus Åhall
27e493945a Better timezone handling 2024-03-30 09:46:48 +01:00
6 changed files with 22 additions and 7 deletions

View File

@ -271,13 +271,14 @@ func nodeUpdate(w http.ResponseWriter, r *http.Request, sess *session.T) { // {{
Content string Content string
CryptoKeyID int CryptoKeyID int
Markdown bool Markdown bool
TimeOffset int
}{} }{}
if err = parseRequest(r, &req); err != nil { if err = parseRequest(r, &req); err != nil {
responseError(w, err) responseError(w, err)
return return
} }
err = UpdateNode(sess.UserID, req.NodeID, req.Content, req.CryptoKeyID, req.Markdown) err = UpdateNode(sess.UserID, req.NodeID, req.TimeOffset, req.Content, req.CryptoKeyID, req.Markdown)
if err != nil { if err != nil {
responseError(w, err) responseError(w, err)
return return

View File

@ -323,9 +323,9 @@ func CreateNode(userID, parentID int, name string) (node Node, err error) { // {
node.Crumbs, err = NodeCrumbs(node.ID) node.Crumbs, err = NodeCrumbs(node.ID)
return return
} // }}} } // }}}
func UpdateNode(userID, nodeID int, content string, cryptoKeyID int, markdown bool) (err error) { // {{{ func UpdateNode(userID, nodeID, timeOffset int, content string, cryptoKeyID int, markdown bool) (err error) { // {{{
var scannedSchedules, dbSchedules, add, remove []Schedule var scannedSchedules, dbSchedules, add, remove []Schedule
scannedSchedules = ScanForSchedules(content) scannedSchedules = ScanForSchedules(timeOffset, content)
for i := range scannedSchedules { for i := range scannedSchedules {
scannedSchedules[i].Node.ID = nodeID scannedSchedules[i].Node.ID = nodeID
scannedSchedules[i].UserID = userID scannedSchedules[i].UserID = userID

View File

@ -26,7 +26,7 @@ type Schedule struct {
Acknowledged bool Acknowledged bool
} }
func ScanForSchedules(content string) (schedules []Schedule) {// {{{ func ScanForSchedules(timeOffset int, content string) (schedules []Schedule) {// {{{
schedules = []Schedule{} schedules = []Schedule{}
rxp := regexp.MustCompile(`\{\s*([0-9]{4}-[0-9]{2}-[0-9]{2}\s+[0-9]{2}:[0-9]{2}(?::[0-9]{2})?)\s*\,\s*([^\]]+?)\s*\}`) rxp := regexp.MustCompile(`\{\s*([0-9]{4}-[0-9]{2}-[0-9]{2}\s+[0-9]{2}:[0-9]{2}(?::[0-9]{2})?)\s*\,\s*([^\]]+?)\s*\}`)
@ -38,7 +38,18 @@ func ScanForSchedules(content string) (schedules []Schedule) {// {{{
data[1] = data[1] + ":00" data[1] = data[1] + ":00"
} }
timestamp, err := time.Parse("2006-01-02 15:04:05", data[1]) var timeTZ string
if timeOffset < 0 {
hours := (-timeOffset) / 60
mins := (-timeOffset) % 60
timeTZ = fmt.Sprintf("%s -%02d%02d", data[1], hours, mins)
} else {
hours := timeOffset / 60
mins := timeOffset % 60
timeTZ = fmt.Sprintf("%s +%02d%02d", data[1], hours, mins)
}
timestamp, err := time.Parse("2006-01-02 15:04:05 -0700", timeTZ)
if err != nil { if err != nil {
continue continue
} }
@ -62,7 +73,7 @@ func RetrieveSchedules(userID int, nodeID int) (schedules []Schedule, err error)
user_id, user_id,
json_build_object('id', node_id) AS node, json_build_object('id', node_id) AS node,
schedule_uuid, schedule_uuid,
time::timestamptz, time,
description, description,
acknowledged acknowledged
FROM schedule FROM schedule

2
sql/00018.sql Normal file
View File

@ -0,0 +1,2 @@
ALTER TABLE public.schedule ALTER COLUMN "time" TYPE timestamptz USING "time"::timestamptz;

View File

@ -485,6 +485,7 @@ export class Node {
Content: this._content, Content: this._content,
CryptoKeyID: this.CryptoKeyID, CryptoKeyID: this.CryptoKeyID,
Markdown: this.Markdown, Markdown: this.Markdown,
TimeOffset: -(new Date().getTimezoneOffset()),
} }
this.app.request('/node/update', req) this.app.request('/node/update', req)
.then(callback) .then(callback)

View File

@ -1 +1 @@
v23 v24