All Projects → hopsor → open_hours

hopsor / open_hours

Licence: MIT license
Time calculations using business hours

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to open hours

Date Picker
📅 Custom responsive date picker widget for Android, written in Kotlin.
Stars: ✭ 146 (+256.1%)
Mutual labels:  time, datetime
date-extractor
Extract dates from text
Stars: ✭ 58 (+41.46%)
Mutual labels:  time, datetime
Gostradamus
Gostradamus: Better DateTimes for Go 🕰️
Stars: ✭ 148 (+260.98%)
Mutual labels:  time, datetime
Tail.datetime
A lightweight, translat- and configurable Open Source DateTime Picker, written in pure vanilla JavaScript!
Stars: ✭ 139 (+239.02%)
Mutual labels:  time, datetime
Blitz
Android Library: Set self-updating string with relative time in TextView (e.g. 5 minutes ago)
Stars: ✭ 217 (+429.27%)
Mutual labels:  time, datetime
Delorean
Delorean: Time Travel Made Easy
Stars: ✭ 1,793 (+4273.17%)
Mutual labels:  time, datetime
Eztime
ezTime — pronounced "Easy Time" — is a very easy to use Arduino time and date library that provides NTP network time lookups, extensive timezone support, formatted time and date strings, user events, millisecond precision and more.
Stars: ✭ 173 (+321.95%)
Mutual labels:  time, datetime
Time Stamp
Get a formatted timestamp. Used in gulp, assemble, generate, and many others.
Stars: ✭ 104 (+153.66%)
Mutual labels:  time, datetime
lit-date
Light-weight, faster datetime formatter for modern browsers.
Stars: ✭ 33 (-19.51%)
Mutual labels:  time, datetime
Dpicker
A framework-agnostic minimal date picker
Stars: ✭ 187 (+356.1%)
Mutual labels:  time, datetime
Dateutil
Useful extensions to the standard Python datetime features
Stars: ✭ 1,706 (+4060.98%)
Mutual labels:  time, datetime
ptera
Ptera is DateTime library for Deno
Stars: ✭ 62 (+51.22%)
Mutual labels:  time, datetime
Human time
Ruby time and date comparisons for humans
Stars: ✭ 113 (+175.61%)
Mutual labels:  time, datetime
Exceptionless.datetimeextensions
DateTimeRange, Business Day and various DateTime, DateTimeOffset, TimeSpan extension methods
Stars: ✭ 142 (+246.34%)
Mutual labels:  time, datetime
Calendar
📅 PHP Date & Time library that solves common problems in object oriented, immutable way.
Stars: ✭ 113 (+175.61%)
Mutual labels:  time, datetime
Time
Building a better date/time library for Swift
Stars: ✭ 1,983 (+4736.59%)
Mutual labels:  time, datetime
Luatz
Time, Date and Timezone library for lua
Stars: ✭ 92 (+124.39%)
Mutual labels:  time, datetime
Dateparse
GoLang Parse many date strings without knowing format in advance.
Stars: ✭ 1,365 (+3229.27%)
Mutual labels:  time, datetime
Date
A date and time library based on the C++11/14/17 <chrono> header
Stars: ✭ 2,389 (+5726.83%)
Mutual labels:  time, datetime
Jiffy
Jiffy is a Flutter (Android, IOS and Web) date time package inspired by momentjs for parsing, manipulating, querying and formatting dates
Stars: ✭ 238 (+480.49%)
Mutual labels:  time, datetime

OpenHours

Build Status Package Version

OpenHours is an Elixir package aimed to help with time calculations using business hours.

It's inspired by the amazing ruby gem biz developed by Zendesk.

Installation

The package can be installed by adding open_hours to your list of dependencies in mix.exs:

def deps do
  [
    {:open_hours, "~> 0.1.0"}
  ]
end

Usage

In order to use OpenHours functions you first need a Schedule config:

schedule = %OpenHours.Schedule{
  hours: %{
    mon: [{~T[09:00:00], ~T[14:00:00]}, {~T[15:00:00], ~T[20:00:00]}],
    tue: [{~T[09:00:00], ~T[14:00:00]}, {~T[15:00:00], ~T[20:00:00]}],
    wed: [{~T[09:00:00], ~T[14:00:00]}, {~T[15:00:00], ~T[20:00:00]}],
    thu: [{~T[09:00:00], ~T[14:00:00]}, {~T[15:00:00], ~T[20:00:00]}]
  },
  holidays: [
    ~D[2019-01-14]
  ],
  shifts: [
    {~D[2019-01-15], [{~T[10:00:00], ~T[15:00:00]}]}
  ],
  breaks: [
    {~D[2019-01-16], [{~T[17:00:00], ~T[20:00:00]}]}
  ],
  time_zone: "Europe/Madrid"
}

There are five settings to configure in a schedule:

  • hours: Map containing all the open hours intervals for a regular week.
  • holidays: List of dates in which the business is closed.
  • shifts: Special dates where the business has a different hour schedule.
  • breaks: Special dates where the business has interruption intervals.
  • time_zone: Time zone of the schedule.

OpenHours offers two main functionalities.

Checking a DateTime is within open hours

> at = DateTime.from_naive!(~N[2019-01-15 14:00:00], "Europe/Madrid", Tzdata.TimeZoneDatabase)
#DateTime<2019-01-15 14:00:00+01:00 CET Europe/Madrid>

> OpenHours.Schedule.in_hours?(schedule, at)
true

> at = DateTime.from_naive!(~N[2019-01-14 12:00:00], "Europe/Madrid", Tzdata.TimeZoneDatabase)
#DateTime<2019-01-14 12:00:00+01:00 CET Europe/Madrid>

> OpenHours.Schedule.in_hours?(schedule, at)
false

Calculate all TimeSlot between two dates

> starts_at = DateTime.from_naive!(~N[2019-01-14 12:00:00], "Europe/Madrid", Tzdata.TimeZoneDatabase)
#DateTime<2019-01-14 12:00:00+01:00 CET Europe/Madrid>

> ends_at = DateTime.from_naive!(~N[2019-01-16 22:00:00], "Europe/Madrid", Tzdata.TimeZoneDatabase)
#DateTime<2019-01-16 22:00:00+01:00 CET Europe/Madrid>

> OpenHours.TimeSlot.between(schedule, starts_at, ends_at)
[
  %OpenHours.TimeSlot{
    ends_at: #DateTime<2019-01-15 15:00:00+01:00 CET Europe/Madrid>,
    starts_at: #DateTime<2019-01-15 10:00:00+01:00 CET Europe/Madrid>
  },
  %OpenHours.TimeSlot{
    ends_at: #DateTime<2019-01-16 14:00:00+01:00 CET Europe/Madrid>,
    starts_at: #DateTime<2019-01-16 09:00:00+01:00 CET Europe/Madrid>
  },
  %OpenHours.TimeSlot{
    ends_at: #DateTime<2019-01-16 17:00:00+01:00 CET Europe/Madrid>,
    starts_at: #DateTime<2019-01-16 15:00:00+01:00 CET Europe/Madrid>
  }
]

License

This software is licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].