A Business DateTime library for Elixir
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
config
lib
test
.gitignore
.travis.yml
LICENSE
README.md
mix.exs

README.md

BizEx

Build Status

Work in Progress. Incomplete. API not stable. Minimal documentation. May contain bugs. Help wanted, etc.

You have been warned.

Adds business hours to a provided datetime, based on a schedule. i.e. if your business is open 9-5, and you add 1 hour after 5, you'll end up with a time the next working day at 10.

Inspired by Biz, business_time, working_hours.

Supports;

  • Shifting time by days, hours, minutes and seconds
  • Multiple time periods per-day
  • Manually defined holidays

Known Issues

  • There are assumptions based on the schedule order. If you do not use the BizEx.Schedule.add_* functions behaviour may not be defined
  • Missing tests
  • Shifting of time is not leap second aware (sorry for my purposes I just really dont need to engineer this in)
  • Minimal module docs - still being worked on
  • Shifting long periods of time may be slow

Getting Started

Installation

def deps do
  [{:bizex, git: "https://github.com/theangryangel/BizEx.git"}]
end

Then, update your dependencies:

$ mix deps.get

Quick introduction

# Create a datetime for us to work with
{:ok, dt, tz} = DateTime.from_iso8601("2017-11-16T16:50:00Z")
#=> {:ok, #DateTime<2017-11-16 16:50:00Z>, 0}

# Get a copy of the bundled default schedule
schedule = BizEx.Schedule.default()

# Add 1 working hour to the date time from above, using the default schedule
BizEx.shift(schedule, dt, hours: 1)
#=> #DateTime<2017-11-17 09:20:00Z>

# Creating and using a custom defined schedule, rather than the default schedule
schedule = %BizEx.Schedule{}
  |> BizEx.Schedule.set_timezone("Europe/London")
  |> BizEx.Schedule.add_period(~T[09:00:00], ~T[17:30:00], :mon)
  |> BizEx.Schedule.add_period(~T[09:00:00], ~T[17:30:00], :tue)
  |> BizEx.Schedule.add_period(~T[09:00:00], ~T[17:30:00], :wed)
  |> BizEx.Schedule.add_period(~T[09:00:00], ~T[17:30:00], :thu)
  |> BizEx.Schedule.add_period(~T[09:00:00], ~T[17:30:00], :fri)
  |> BizEx.Schedule.add_holiday(~D[2017-12-25])

BizEx.shift(schedule, dt, hours: 1)
#=> {:ok, #DateTime<2017-11-16 16:50:00Z>, 0}