zendesk/biz là một trong những repo phía máy chủ mà TopGit theo dõi, hiện có 487 sao, viết chủ yếu bằng Ruby. Time calculations using business hours.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Configured timestamps must be in either HH:MM or HH:MM:SS format.
Shifts act as exceptions to the hours configured for a particular date; that is,
if a date is configured with both hours-based intervals and shifts, the shifts
are in force and the intervals are disregarded.
Periods occurring on holidays are disregarded. Similarly, any segment of a
period that overlaps with a break is treated as inactive.
If global configuration isn't your thing, configure an instance instead:
Biz::Schedule.new do |config|
# ...
end
Note that times must be specified in 24-hour clock format and time zones
must be IANA identifiers.
If you're operating in a threaded environment and want to use the same
configuration across threads, save the configured schedule as a global variable:
$biz = Biz::Schedule.new
Usage
# Find the time an amount of business time *before* a specified starting time
Biz.time(30, :minutes).before(Time.utc(2015, 1, 1, 11, 45))
# Find the time an amount of business time *after* a specified starting time
Biz.time(2, :hours).after(Time.utc(2015, 12, 25, 9, 30))
# Calculations can be performed in seconds, minutes, hours, or days
Biz.time(1, :day).after(Time.utc(2015, 1, 8, 10))
# Find the previous business time
Biz.time(0, :hours).before(Time.utc(2016, 1, 8, 6))
# Find the next business time
Biz.time(0, :hours).after(Time.utc(2016, 1, 8, 20))
# Find the amount of business time between two times
Biz.within(Time.utc(2015, 3, 7), Time.utc(2015, 3, 14)).in_seconds
# Find the start of the business day
Biz.periods.on(Date.today).first.start_time
# Find the end of the business day
Biz.periods.on(Date.today).to_a.last.end_time
# Determine if a time is in business hours
Biz.in_hours?(Time.utc(2015, 1, 10, 9))
# Determine if a time is during a break
Biz.on_break?(Time.utc(2016, 6, 3))
# Determine if a time is during a holiday
Biz.on_holiday?(Time.utc(2014, 1, 1))
The same methods can be called on a configured instance:
If a schedule will be configured with a large number of holidays and performance
is a particular concern, it's recommended that holidays are filtered down to
those relevant to the calculation(s) at hand before configuration to improve
performance.
By dropping down a level, you can get access to the underlying time segments,
which you can use to do your own custom calculations or just get a better idea
of what's happening under the hood:
Biz.periods.after(Time.utc(2015, 1, 10, 10)).timeline
.until(Time.utc(2015, 1, 17, 10)).to_a
#=> [#<Biz::TimeSegment start_time=2015-01-10 18:00:00 UTC end_time=2015-01-10 22:00:00 UTC>,
# #<Biz::TimeSegment start_time=2015-01-12 17:00:00 UTC end_time=2015-01-13 01:00:00 UTC>,
# #<Biz::TimeSegment start_time=2015-01-13 08:00:00 UTC end_time=2015-01-14 08:00:00 UTC>,
# #<Biz::TimeSegment start_time=2015-01-14 17:00:00 UTC end_time=2015-01-15 01:00:00 UTC>,
# #<Biz::TimeSegment start_time=2015-01-15 17:00:00 UTC end_time=2015-01-15 20:00:00 UTC>,
# #<Biz::TimeSegment start_time=2015-01-15 21:00:00 UTC end_time=2015-01-16 01:00:00 UTC>]
Biz.periods
.before(Time.utc(2015, 5, 5, 12, 34, 57)).timeline
.for(Biz::Duration.minutes(3_598)).to_a
#=> [#<Biz::TimeSegment start_time=2015-05-05 07:00:00 UTC end_time=2015-05-05 12:34:57 UTC>,
# #<Biz::TimeSegment start_time=2015-05-04 16:00:00 UTC end_time=2015-05-05 00:00:00 UTC>,
# #<Biz::TimeSegment start_time=2015-05-02 17:00:00 UTC end_time=2015-05-02 21:00:00 UTC>,
# #<Biz::TimeSegment start_time=2015-04-30 20:00:00 UTC end_time=2015-05-01 00:00:00 UTC>,
# #<Biz::TimeSegment start_time=2015-04-30 16:00:00 UTC end_time=2015-04-30 19:00:00 UTC>,
# #<Biz::TimeSegment start_time=2015-04-29 16:00:00 UTC end_time=2015-04-30 00:00:00 UTC>,
# #<Biz::TimeSegment start_time=2015-04-28 07:00:00 UTC end_time=2015-04-29 07:00:00 UTC>,
# #<Biz::TimeSegment start_time=2015-04-27 20:36:57 UTC end_time=2015-04-28 00:00:00 UTC>]
Day calculation semantics
Unlike seconds, minutes, or hours, a "day" is an ambiguous concept, particularly
in relation to the vast number of potential schedule configurations. Because of
that, day calculations are implemented with the principle of making the logic as
straightforward as possible while knowing not all use cases will be satisfied
out of the box.
Here's the logic that's followed:
Find the next day that contains business hours. Starting from the same minute
on that day as the specified time, look forward (or back) to find the next
moment in time that is in business hours.
Schedule intersection
An intersection of two schedules can be found using &:
The resulting schedule will be a combination of the two schedules: an
intersection of the intervals, a union of the breaks and holidays,
and the time zone of the first schedule. Any configured shifts will be
disregarded.
For the above example, the resulting schedule would be equivalent to one with
the following configuration:
Pull requests are welcome, but consider asking for a feature or bug fix first
through the issue tracker. When contributing code, please squash sloppy commits
aggressively and follow Tim Pope's guidelines
for commit messages.
There are a number of ways to get started after cloning the repository.
To set up your environment:
script/bootstrap
To run the spec suite:
script/spec
To open a console with the gem and sample schedule loaded:
script/console
Alternatives
business_time
working_hours
Copyright and license
Copyright 2015-19 Zendesk
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this gem except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/zendesk/biz là nguồn chính thức.
zendesk/biz có bao nhiêu sao?
zendesk/biz có 487 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/zendesk/biz. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
zendesk/biz có phải mã nguồn mở không?
Có — zendesk/biz phát hành theo license Apache-2.0, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/zendesk/biz.
zendesk/biz còn đang phát triển không?
Commit gần nhất trên zendesk/biz là 2 tháng trước (theo timestamp GitHub). Repo có 24 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
zendesk/biz là gì?
zendesk/biz (zendesk/biz) là dự án Ruby trên GitHub. Theo mô tả gốc: Time calculations using business hours.
zendesk/biz so với các dự án Backend khác thế nào?
zendesk/biz được TopGit xếp vào nhóm Backend, với 487 sao GitHub và viết bằng Ruby. Xem trang chủ đề Backend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về biz?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về biz.