M src/Text/HTML/Form/WebApp.hs => src/Text/HTML/Form/WebApp.hs +5 -4
@@ 17,7 17,7 @@ import Text.HTML.Form.WebApp.Ginger (template, template', resolveSource, list')
import Text.HTML.Form.Query (renderQueryString, renderQuery')
import Text.HTML.Form.WebApp.Ginger.Hourglass (timeData, modifyTime', timeParseOrNow,
gSeqTo, gPad2)
-import Text.HTML.Form.WebApp.Ginger.TZ (tzdata)
+import Text.HTML.Form.WebApp.Ginger.TZ (tzdata, continents)
import Text.Ginger.GVal as V (GVal(..), toGVal, orderedDict, (~>), fromFunction)
import Text.Ginger.Html (html)
@@ 42,12 42,13 @@ renderInput form ix input@Input { inputType = "date", inputName = name } ["year"
\prop -> case prop of
"T" -> timeData t'
_ -> toGVal ()
-renderInput form ix input@Input { inputType = "date", inputName = name } ["zone", ""] qs = do
+renderInput form ix input@Input { inputType = "date", inputName = name } ["zone", p] qs = do
t <- timeParseOrNow $ get name qs
let Elapsed (Seconds t') = timeGetElapsed $ localTimeToGlobal t
- template' "cal/year-numpad.html" form ix input qs $ \prop -> case prop of
+ template' "cal/timezone.html" form ix input qs $ \prop -> case prop of
"T" -> timeData t
- "zones" -> tzdata t'
+ "zones" -> tzdata t' $ unEscapeString $ Txt.unpack p
+ "continents" -> continents
_ -> toGVal ()
renderInput form ix input@Input { multiple = True } [p] qs
| '=':v' <- Txt.unpack p,
M src/Text/HTML/Form/WebApp/Ginger/TZ.hs => src/Text/HTML/Form/WebApp/Ginger/TZ.hs +23 -6
@@ 1,20 1,37 @@
{-# LANGUAGE OverloadedStrings #-}
-module Text.HTML.Form.WebApp.Ginger.TZ(tzdata) where
+module Text.HTML.Form.WebApp.Ginger.TZ(tzdata, continents) where
-import Text.Ginger.GVal as V (GVal, orderedDict, (~>), list)
+import Text.Ginger.GVal as V (GVal, toGVal, orderedDict, (~>), list)
import qualified Data.Map.Strict as M
import Data.Time.Zones.All (tzNameLabelMap, tzByLabel)
import Data.Time.Zones (diffForPOSIX)
+
import Data.Int (Int64)
+import Data.List (nub)
+import qualified Data.ByteString as BS
+import qualified Data.ByteString.Char8 as BSC
-tzdata :: Int64 -> GVal m
-tzdata now = list [orderedDict [
+tzdata :: Int64 -> String -> GVal m
+tzdata now prefix = list [orderedDict [
"label" ~> label,
"value" ~> (diffForPOSIX tz' now `div` 60),
"offset" ~> formatOffset (diffForPOSIX tz' now `div` 60)
- ] | (label, tz) <- M.toList tzNameLabelMap, let tz' = tzByLabel tz]
+ ] | (label, tz) <- M.toList tzNameLabelMap,
+ BSC.pack prefix `contains` label,
+ let tz' = tzByLabel tz]
+ where
+ contains "" = BSC.notElem '/'
+ contains "..." = BSC.notElem '/'
+ contains x = BS.isPrefixOf x
formatOffset :: (Show a, Integral a) => a -> [Char]
-formatOffset offset = (show hours ++ ':': show minutes)
+formatOffset offset
+ | minutes < 10 = show hours ++ ':':'0': show minutes
+ | otherwise = show hours ++ ':': show minutes
where
hours = offset `div` 60
minutes = abs $ offset `rem` 60
+
+continents :: GVal m
+continents = list $ map toGVal $ nub $ "...":[prefix |
+ (label, _) <- M.toList tzNameLabelMap,
+ let (prefix, _) = BSC.breakEnd (== '/') label]
M tpl/cal/timezone.html => tpl/cal/timezone.html +8 -3
@@ 1,8 1,13 @@
{% extends "/base.html" %}
{%- block main -%}<section>
- <h2><a href="..">{{ T.timezone }}</a></h2>
- <ul style="display: grid; gap: 5px; grid-template-columns: repeat(6, min-content); list-style-type: none">{% for tz in timezones %}
+ <ul style="list-style: none">{% for cont in continents %}
+ <li><a href="{{cont|xURI}}">{{ cont }}</a></li>
+ {% endfor %}</ul>
+</section>
+<section>
+ <h2><a href="..">{{ T.zone }}</a></h2>
+ <ul style="display: flex; flex-wrap: wrap; justify-content: space-between; list-style: none">{% for tz in zones %}
<li><a href="../zone={{tz.value}}">{{ tz.label }}</a> ({{ tz.offset }})</li>
{% endfor %}</ul>
-</section>{% - endblock %-}
+</section>{%- endblock -%}
D tpl/cal/year-numpad.html~ => tpl/cal/year-numpad.html~ +0 -34
@@ 1,34 0,0 @@
-{% extends "base.html" %}
-
-{%- block main -%}<section>
- <p><a href="+-{{input.step|default(1)}}{{Q}}">↓</a>
- {{ input.value }}
- <a href="+{{input.step|default(1)}}{{Q}}">↑</a></p>
- <hr />
- <table>
- <tr>
- <td><a href=":7{{Q}}">7</a></td>
- <td><a href=":8{{Q}}">8</a></td>
- <td><a href=":9{{Q}}">9</a></td>
- <td><a href=":-{{Q}}">-</a></td>
- </tr>
- <tr>
- <td><a href=":4{{Q}}">4</a></td>
- <td><a href=":5{{Q}}">5</a></td>
- <td><a href=":6{{Q}}">6</a></td>
- <td><a href=":%20{{Q}}">SPACE</a></td>
- </tr>
- <tr>
- <td><a href=":1{{Q}}">1</a></td>
- <td><a href=":2{{Q}}">2</a></td>
- <td><a href=":3{{Q}}">3</a></td>
- <td><a href="-{{Q}}">DEL</a></td>
- </tr>
- <tr>
- <td><a href=":.{{Q}}">.</a></td>
- <td><a href=":0{{Q}}">0</a></td>
- <td><a href=":,{{Q}}">,</a></td>
- <td><a href="={{Q}}">CLEAR</a></td>
- </tr>
- </table>
-</section>{%- endblock -%}
M tpl/gregorian.html => tpl/gregorian.html +1 -1
@@ 33,7 33,7 @@
<a href="meridiem{{Q}}" title="Toggle AM/PM">{{ T.meridiem }}</a>
<a href="-zone{{Q}}" title="Previous timezone">↓</a>
- <a href="zone/">{{ T.zone }}</a>
+ <a href="zone/{{Q}}">{{ T.zone }}</a>
<a href="+zone{{Q}}" title="Next zone">↑</a></p>
<p><a href="now{{Q}}" title="Select current date & time">Now</a></a>
M tpl/number.html => tpl/number.html +1 -1
@@ 1,6 1,6 @@
{% extends "base.html" %}
-{%- block control -%}<section>
+{%- block main -%}<section>
<p><a href="+-{{input.step|default(1)}}{{Q}}">↓</a>
{{ input.value }}
<a href="+{{input.step|default(1)}}{{Q}}">↑</a></p>