Giter Club home page Giter Club logo

elm-calendar's Introduction

elm-calendar

A "sorta-port" of the Unix cal command to Elm. Outputs a "calendar grid" data structure that is very useful for creating datepickers, planners, and other UI widgets that are based around calendar months.

This library depends on the justinmimbs/date package to represent dates in a non-timezone specific manner.

The fromDate and fromTime functions output a List of Lists of data structures containing a Date. Each List has a length of exactly seven and is padded as necessary with dates from the next/previous month.

import Calendar exposing (fromTime)
import Time exposing (utc, Posix, millisToPosix)

july14th2020 =
    millisToPosix 1594725024442


july14th2020calendar =
    fromTime Nothing utc july14th2020

You can also initialize a calendar from a Date.

import Calendar exposing (fromDate)
import Date exposing (fromCalendarDate)
import Time exposing (Month(..))

july14th2020 =
    fromCalendarDate 2020 Jul 14

july14th2020calendar =
    fromDate Nothing july14th2020

By default the week starts on Sunday, which is weekdayNumber == 7. This is configurable via the first argument to either fromTime or fromDate

Weekday numbers is 1-7 starting with Monday and ending with Sunday.

import Calendar exposing (fromTime)
import Time exposing (utc, Posix, millisToPosix)

july14th2020 =
    millisToPosix 1594725024442


startOnMonday =
    fromTime
        (Just { startWeekdayNumber = 1 })
        utc
        july14th2020

The print function can output a visualization of the calendar. For example, the calendar for July 2020 would print:

          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   

elm-calendar's People

Contributors

abradley2 avatar magnarn avatar

Stargazers

Vidak Kazic avatar Chew Choon Keat avatar Ralf Northman avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

magnarn

elm-calendar's Issues

Consider using Array2d

Cool package!

One suggestion though. Instead of returning List (List CalendarDate) I think it would be better to use Array2d from tortus/elm-array-2d. That way there isn't confusion around whether you are returning calendar dates with rows first or columns first.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.