How can I display the current time zone offset in GMT, in Elm

I am stuck in getting the current timezone offset from the date in the knit.

Date.now

This returns <Thu Feb 22 2018 20:42:42 GMT+0530 (India Standard Time)>as a string. Since I examined the date and time in Elm core lib, they do not provide any direct method for retrieving the current time zone offset. So what should I do?

import Html as App
import Html exposing (..)
import Date exposing (Date)
import Task


type alias Model = 
  Maybe Date


type Msg = 
  SetDate (Maybe Date)


update : Msg -> Model -> (Model, Cmd Msg)
update (SetDate date) _ = 
  (date, Cmd.none)


view : Model -> Html Msg
view model =
  div [] [ text <| dateString model ]


dateString : Model -> String
dateString model =
  case model of
    Nothing -> "No date here"
    Just date ->
      (toString <| date)

now : Cmd Msg
now = 
  Task.perform (Just >> SetDate) Date.now




main : Program Never Model Msg
main =
  App.program 
    { init = ( Nothing, now ) 
    , view = view
    , subscriptions = always Sub.none 
    , update = update
    }

I need this +0530as in a float 5.5.

+4
source share
1 answer

The Elm DateTime functions are currently pretty meager, but justinmimbs. The Date.Extra library is my approach to solving this problem. Check here

You can import it as such,

import Date.Extra exposing (offsetFromUtc)

And then, when you toString <| datechanged your pipeline to

date
    |> offsetFromUtc
    |> toString

, float, int 60. :

divBy60 : Int -> Float
divBy60 t =
    toFloat t / 60.0

date
    |> offsetFromUtc
    |> divBy60
    |> toString
+6

Source: https://habr.com/ru/post/1694026/


All Articles