Showing with 16 additions and 6 deletions.
  1. +4 −4 Chapter7/Tweeter/src/database.nim
  2. +1 −1 Chapter7/Tweeter/src/tweeter.nim
  3. +1 −1 Chapter7/Tweeter/src/views/user.nim
  4. +10 −0 readme.md
8 changes: 4 additions & 4 deletions Chapter7/Tweeter/src/database.nim
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ proc post*(database: Database, message: Message) =
raise newException(ValueError, "Message has to be less than 140 characters.")

database.db.exec(sql"INSERT INTO Message VALUES (?, ?, ?);", #<2>
message.username, $message.time.toSeconds().int, message.msg) #<3>
message.username, $message.time.toUnix().int, message.msg) #<3>

proc follow*(database: Database, follower: User, user: User) =
database.db.exec(sql"INSERT INTO Following VALUES (?, ?);",#<2>
Expand Down Expand Up @@ -79,9 +79,9 @@ proc findMessages*(database: Database, usernames: seq[string],
result = @[]
if usernames.len == 0: return
var whereClause = " WHERE "
for i in 0 .. <usernames.len:
for i in 0 ..< usernames.len:
whereClause.add("username = ? ")
if i != <usernames.len:
if i != pred(usernames.len):
whereClause.add("or ")

let messages = database.db.getAllRows(
Expand All @@ -90,4 +90,4 @@ proc findMessages*(database: Database, usernames: seq[string],
"ORDER BY time DESC LIMIT " & $limit),
usernames)
for row in messages:
result.add(Message(username: row[0], time: fromSeconds(row[1].parseInt), msg: row[2]))
result.add(Message(username: row[0], time: fromUnix(row[1].parseInt), msg: row[2]))
2 changes: 1 addition & 1 deletion Chapter7/Tweeter/src/tweeter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ routes:
redirect(uri("/" & @"target"))

post "/login":
setCookie("username", @"username", getTime().getGMTime() + 2.hours)
setCookie("username", @"username", getTime().utc() + 2.hours)
redirect("/")

post "/createMessage":
Expand Down
2 changes: 1 addition & 1 deletion Chapter7/Tweeter/src/views/user.nim
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#for message in messages:
<div>
<a href="/${message.username}">${message.username}</a>
<span>${message.time.getGMTime().format("HH:mm MMMM d',' yyyy")}</span>
<span>${message.time.utc().format("HH:mm MMMM d',' yyyy")}</span>
<h3>${message.msg}</h3>
</div>
#end for
Expand Down
10 changes: 10 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ This repository contains the source code for all the projects developed inside t
**FAQ**: https://github.com/dom96/nim-in-action-code/wiki/FAQ

**Errata for Nim 1.0**: https://deepakg.github.io/nim/2019/09/28/nim-in-action-errata.html

## Nim Version Compatibility

| Branch | v0.17.2 | v1.0.6 | v1.2.6 |
| ------------------------------------------------------------------------ |:-------------:|:-------:|:------:|
| [`master`](https://github.com/dom96/nim-in-action-code/tree/master) | ✔️ | ✔️ ||
| [`v1.2.6`](https://github.com/dom96/nim-in-action-code/tree/v1.2.6) || ✔️ | ✔️ |


> :information_source: The `master` branch holds the code that reflects what is in Nim in Action. Other branches contain code modified to work with later versions of Nim.