Compare commits
2 Commits
aee1c25f54
...
d89d63803f
Author | SHA1 | Date | |
---|---|---|---|
|
d89d63803f | ||
|
27e493945a |
3
main.go
3
main.go
@ -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
|
||||||
|
4
node.go
4
node.go
@ -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
|
||||||
|
17
schedule.go
17
schedule.go
@ -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
2
sql/00018.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE public.schedule ALTER COLUMN "time" TYPE timestamptz USING "time"::timestamptz;
|
||||||
|
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user