Changeset 784 in code for trunk


Ignore:
Timestamp:
Feb 16, 2022, 1:45:09 PM (3 years ago)
Author:
contact
Message:

Introduce formatServerTime

It's too easy to forget to convert to UTC.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/bridge.go

    r781 r784  
    2828                        timestampStr := "*"
    2929                        if r != nil {
    30                                 timestampStr = fmt.Sprintf("timestamp=%s", r.Timestamp.UTC().Format(serverTimeLayout))
     30                                timestampStr = fmt.Sprintf("timestamp=%s", formatServerTime(r.Timestamp))
    3131                        }
    3232                        dc.SendMessage(&irc.Message{
  • trunk/db_sqlite.go

    r781 r784  
    796796        args := []interface{}{
    797797                sql.Named("id", receipt.ID),
    798                 sql.Named("timestamp", receipt.Timestamp.UTC().Format(serverTimeLayout)),
     798                sql.Named("timestamp", formatServerTime(receipt.Timestamp)),
    799799                sql.Named("network", networkID),
    800800                sql.Named("target", receipt.Target),
  • trunk/downstream.go

    r783 r784  
    23312331
    23322332                                broadcastTags := tags.Copy()
    2333                                 broadcastTags["time"] = irc.TagValue(time.Now().UTC().Format(serverTimeLayout))
     2333                                broadcastTags["time"] = irc.TagValue(formatServerTime(time.Now()))
    23342334                                broadcastMsg := &irc.Message{
    23352335                                        Tags:    broadcastTags,
     
    23572357                                if dc.caps["echo-message"] {
    23582358                                        echoTags := tags.Copy()
    2359                                         echoTags["time"] = irc.TagValue(time.Now().UTC().Format(serverTimeLayout))
     2359                                        echoTags["time"] = irc.TagValue(formatServerTime(time.Now()))
    23602360                                        dc.SendMessage(&irc.Message{
    23612361                                                Tags:    echoTags,
     
    23892389
    23902390                        echoTags := tags.Copy()
    2391                         echoTags["time"] = irc.TagValue(time.Now().UTC().Format(serverTimeLayout))
     2391                        echoTags["time"] = irc.TagValue(formatServerTime(time.Now()))
    23922392                        if uc.account != "" {
    23932393                                echoTags["account"] = irc.TagValue(uc.account)
     
    24402440
    24412441                        echoTags := tags.Copy()
    2442                         echoTags["time"] = irc.TagValue(time.Now().UTC().Format(serverTimeLayout))
     2442                        echoTags["time"] = irc.TagValue(formatServerTime(time.Now()))
    24432443                        if uc.account != "" {
    24442444                                echoTags["account"] = irc.TagValue(uc.account)
     
    27372737                                                Prefix:  dc.srv.prefix(),
    27382738                                                Command: "CHATHISTORY",
    2739                                                 Params:  []string{"TARGETS", target.Name, target.LatestMessage.UTC().Format(serverTimeLayout)},
     2739                                                Params:  []string{"TARGETS", target.Name, formatServerTime(target.LatestMessage)},
    27402740                                        })
    27412741                                }
     
    28332833                timestampStr := "*"
    28342834                if !r.Timestamp.IsZero() {
    2835                         timestampStr = fmt.Sprintf("timestamp=%s", r.Timestamp.UTC().Format(serverTimeLayout))
     2835                        timestampStr = fmt.Sprintf("timestamp=%s", formatServerTime(r.Timestamp))
    28362836                }
    28372837                uc.forEachDownstream(func(d *downstreamConn) {
  • trunk/irc.go

    r778 r784  
    3131// The server-time layout, as defined in the IRCv3 spec.
    3232const serverTimeLayout = "2006-01-02T15:04:05.000Z"
     33
     34func formatServerTime(t time.Time) string {
     35        return t.UTC().Format(serverTimeLayout)
     36}
    3337
    3438type userModes string
  • trunk/msgstore_fs.go

    r668 r784  
    381381        msg := &irc.Message{
    382382                Tags: map[string]irc.TagValue{
    383                         "time": irc.TagValue(t.UTC().Format(serverTimeLayout)),
     383                        "time": irc.TagValue(formatServerTime(t)),
    384384                },
    385385                Prefix:  prefix,
  • trunk/upstream.go

    r781 r784  
    446446
    447447        if _, ok := msg.Tags["time"]; !ok {
    448                 msg.Tags["time"] = irc.TagValue(time.Now().UTC().Format(serverTimeLayout))
     448                msg.Tags["time"] = irc.TagValue(formatServerTime(time.Now()))
    449449        }
    450450
Note: See TracChangeset for help on using the changeset viewer.