1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 import parseutils, times, json
proc toAlphaId* (n: int): string =
let chars = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var tmp = n
var digitValue: int = 1
var digit: int = 0
while tmp > 0:
digitValue *= chars.len
digit = tmp mod digitValue
let char = int(digit * chars.len / digitValue)
result = $(chars[char]) & result
tmp -= digit
proc fromAlphaId* (s: string): int =
let chars = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for char in s:
result *= chars.len
result += chars.skipUntil(char)
proc iso8601toUnix* (iso8601string: string): int64 =
let date = parse(iso8601string, "yyyy-MM-dd'T'HH:mm:sszzz")
return toUnix(toTime(date))
proc mergeJObjects* (root: JsonNode, new: JsonNode): JsonNode =
result = root
for key, value in new:
result.add(key, value)