Better timezone handling
This commit is contained in:
parent
aee1c25f54
commit
27e493945a
3
main.go
3
main.go
@ -271,13 +271,14 @@ func nodeUpdate(w http.ResponseWriter, r *http.Request, sess *session.T) { // {{
|
||||
Content string
|
||||
CryptoKeyID int
|
||||
Markdown bool
|
||||
TimeOffset int
|
||||
}{}
|
||||
if err = parseRequest(r, &req); err != nil {
|
||||
responseError(w, err)
|
||||
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 {
|
||||
responseError(w, err)
|
||||
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)
|
||||
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
|
||||
scannedSchedules = ScanForSchedules(content)
|
||||
scannedSchedules = ScanForSchedules(timeOffset, content)
|
||||
for i := range scannedSchedules {
|
||||
scannedSchedules[i].Node.ID = nodeID
|
||||
scannedSchedules[i].UserID = userID
|
||||
|
17
schedule.go
17
schedule.go
@ -26,7 +26,7 @@ type Schedule struct {
|
||||
Acknowledged bool
|
||||
}
|
||||
|
||||
func ScanForSchedules(content string) (schedules []Schedule) {// {{{
|
||||
func ScanForSchedules(timeOffset int, content string) (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*\}`)
|
||||
@ -38,7 +38,18 @@ func ScanForSchedules(content string) (schedules []Schedule) {// {{{
|
||||
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 {
|
||||
continue
|
||||
}
|
||||
@ -62,7 +73,7 @@ func RetrieveSchedules(userID int, nodeID int) (schedules []Schedule, err error)
|
||||
user_id,
|
||||
json_build_object('id', node_id) AS node,
|
||||
schedule_uuid,
|
||||
time::timestamptz,
|
||||
time,
|
||||
description,
|
||||
acknowledged
|
||||
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,
|
||||
CryptoKeyID: this.CryptoKeyID,
|
||||
Markdown: this.Markdown,
|
||||
TimeOffset: -(new Date().getTimezoneOffset()),
|
||||
}
|
||||
this.app.request('/node/update', req)
|
||||
.then(callback)
|
||||
|
Loading…
Reference in New Issue
Block a user