<commit_before>= ActsAsWorkingDays

acts_as_working_days is a Rails plugin to add working days on models

== Usage

 #app/models/company.rb
 class Company < ActiveRecord::Base
 
   acts_as_working_days
 
 end

 #Sample test code 
 def test_working_day
 
  kwik_e_mart = Company.new(:name => 'Kwik-E-Mart')

  #1 is Monday, Apu Kwik-E-Mart is only opened on Mondays from 8h30 till 18h45
  kwik_e_mart.working_days.build(:week_day => 1, :start_hour => 8, :start_min => 30, :end_hour => 18, :end_min => 45)

  #Save model and working day
  kwik_e_mart.save

  #0 = Sunday, 12h45 is closed 
  assert_equal false, kwik_e_mart.working_day?(:week_day => 0, :hour => 12, :min => 0)

  #1 = Monday, 21h00 is closed 
  assert_equal false, kwik_e_mart.working_day?(:week_day => 1, :hour => 21)

  #1 = Monday, 12h15 is opened 
  assert_equal true, kwik_e_mart.working_day?(:week_day => 1, :hour => 12, :min => 15)

 end

 #app/views/company/new.html.erb
 <% form_for @company do |f| %>
	<%= f.error_messages %>
	<h2>Company fields</h2>
	<p>
		<%= f.label :name, 'Company name' %><br/>
		<%= f.text_field :name %>
	</p>
	<h2>Workings days</h2>
	<table id="table-working-days">
	  <thead>
	    <tr>
		  <th>Day</th>
		  <th>Open</th>
		  <th>Close</th>
	    </tr>
	  </thead>
	  <tbody>
	    <% f.fields_for :working_days, @address.working_days_defaults do | working_day_form | %>
		  <tr>
		    <!-- I18n week_day.day_0...day_6, Sunday..Saturday -->
		    <td><%=  t "week_day.day_#{working_day_form.object.week_day}" %></td>
		    <td>
			  <%= working_day_form.hidden_field :week_day %>
			  <%= working_day_form.select :start_hour, 0..23, {}, {:class => 'select'}  %>
			  <%= working_day_form.select :start_min, 0..59, {}, {:class => 'select'}  %>
		    </td>
	  	    <td>
			  <%= working_day_form.select :end_hour, 0..23, {}, {:class => 'select'}  %>
			  <%= working_day_form.select :end_min, 0..59, {}, {:class => 'select'}  %>
		    </td>
		  </tr>
	    <% end %>
	  </tbody>
	<table>
 <% end %>
	
 #config/locales/en.yml
 week_day:
   day_0: Sunday
   day_1: Monday
   day_2: Tuesday
   day_3: Wednesday
   day_4: Thursday
   day_5: Friday
   day_6: Saturday
  

== Installation

=== Rails 2.3.x

Acts As Working Days On is tested to work in Rails 2.3.5. 

==== Plugin

  script/plugin install git://github.com/phstc/acts_as_working_days

==== Post Installation
<commit_msg>Adding time zone information<commit_after>= ActsAsWorkingDays

acts_as_working_days is a Rails plugin to add working days on models

== Usage

=== Adding acts_as_working_days

 # app/models/company.rb
 class Company < ActiveRecord::Base
 
   acts_as_working_days
 
 end

=== Detecting working day

 kwik_e_mart = Company.new(:name => 'Kwik-E-Mart')
 
 # Verifies if kwik_e_mart is opened now (Time.now)
 kwik_e_mart.working_day? 
 
 # Verifies if kwik_e_mart is opened on Sundays
 kwik_e_mart.working_day?(:week_day => 0)
 
 # Verifies if kwik_e_mart is opened on Mondays 21h30
 kwik_e_mart.working_day?(:week_day => 1, :hour => 21, :min => 30)

week_day is an integer representing the day of the week, 0..6, with Sunday == 0
(See http://www.ruby-doc.org/core/classes/Time.html#M000285)

=== Setting working day

 kwik_e_mart = Company.new(:name => 'Kwik-E-Mart')

 # Set kwik_e_mart is opened on Mondays from 8h30 to 18h45
 kwik_e_mart.working_days.build(:week_day => 1, :start_hour => 8, :start_min => 30, :end_hour => 18, :end_min => 45)

 # Set kwik_e_mart is opened on Saturdays from 10h00 to 16h00
 kwik_e_mart.working_days.build(:week_day => 6, :start_hour => 10, :start_min => 0, :end_hour => 16, :end_min => 0)
 
 # retuns true
 kwik_e_mart.working_day?(:week_day => 1)

 # returns true
 kwik_e_mart.working_day?(:week_day => 1, :hour => 18)

 # return true
 kwik_e_mart.working_day?(:week_day => 1, :hour => 12, :min => 30)

 # return false
 kwik_e_mart.working_day?(:week_day => 1, :hour => 21, :min => 30)

=== Creating html form to set the working days

 # app/views/company/new.html.erb
 <% form_for @company do |f| %>
	<%= f.error_messages %>
	<h2>Company fields</h2>
	<p>
		<%= f.label :name, 'Company name' %><br/>
		<%= f.text_field :name %>
	</p>
	<h2>Workings days</h2>
	<table id="table-working-days">
	  <thead>
	    <tr>
		  <th>Day</th>
		  <th>Open</th>
		  <th>Close</th>
	    </tr>
	  </thead>
	  <tbody>
	    <% f.fields_for :working_days, @address.working_days_defaults do | working_day_form | %>
		  <tr>
		    <!-- I18n week_day.day_0...day_6, Sunday..Saturday -->
		    <td><%=  t "week_day.day_#{working_day_form.object.week_day}" %></td>
		    <td>
			  <%= working_day_form.hidden_field :week_day %>
			  <%= working_day_form.select :start_hour, 0..23, {}, {:class => 'select'}  %>
			  <%= working_day_form.select :start_min, 0..59, {}, {:class => 'select'}  %>
		    </td>
	  	    <td>
			  <%= working_day_form.select :end_hour, 0..23, {}, {:class => 'select'}  %>
			  <%= working_day_form.select :end_min, 0..59, {}, {:class => 'select'}  %>
		    </td>
		  </tr>
	    <% end %>
	  </tbody>
	<table>
 <% end %>

=== Creating I18n file to translate numeric week day to string
	
 #config/locales/en.yml
 week_day:
   day_0: Sunday
   day_1: Monday
   day_2: Tuesday
   day_3: Wednesday
   day_4: Thursday
   day_5: Friday
   day_6: Saturday
  

=== Setting rails application time zone

Don't forget to set the time zone in your Rails application enviroment 

 # config/enviroment.rb
 Rails::Initializer.run do |config|
   #...
   config.time_zone = 'Brasilia'
   #...
 end

To list all supported time zones 
 $ rake time:zones:all

(See http://wiki.rubyonrails.org/howtos/time-zones)

== Installation

=== Rails 2.3.x

Acts As Working Days On is tested to work in Rails 2.3.5. 

==== Plugin

  script/plugin install git://github.com/phstc/acts_as_working_days

==== Post Installation

{'fraction_non_alphanumeric': 0.15826717293752157, 'fraction_numerical': 0.02968588194684156, 'mean_word_length': 3.34407796101949, 'pattern_counts': {'":': 0, '<': 91, '<?xml version=': 0, '>': 136, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1813644', 'n_tokens_mistral': 2506, 'n_tokens_neox': 2174, 'n_words': 518}