ctucx.git: oeffi-web

[nimlang] oeffisearch fork that works without javascript

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 
32 
33 
34 
35 
36 
37 
38 
import options, math, times
import nimhafas

proc formatPoint* (point: Point): string {.exportc.} =
  if not point.location.isNone:
    let location = point.location.get

    if not location.name.isNone:
      return location.name.get
    else:
      return location.address.get

  else:
    let stop =  point.stop.get
    return stop.name

proc formatDuration* (duration: int64): string {.exportc.} = 
  let mins = system.div(duration, 60)

  let h = floorDiv(mins, 60)
  let m = floorMod(mins, 60)

  if h > 0:
    return $h & "h " & $m & "min";

  return $m & "min"

proc formatTime* (timestamp: int64, mode: string): string {.exportc.} =
  var time = fromUnix(timestamp)

  if mode != "date":
    result = time.format("HH:mm")

    if now().format("ddMMYYYY") !=  time.format("ddMMYYYY"):
      result &= ", " & time.format("dd'.'MM")

  else:
    result = time.format("dd'.'MM'.'YYYY")