如果我转换为较粗略的时间单位(比如class Employee::ProfilesController < EmployeeController
before_action :set_company_employee
...
def set_company_employee
if params[:employee_id]
# Line that throws error below :
@employee = (Company::Employee).find(params[:employee_id])
else
# Many employee profiles, bad request
flashy_now(:error, :select_employee_profiles)
redirect_back
end
@company = @employee.company
end
class Company::Employee < Professional
include Invitable
belongs_to :company
belongs_to :entity
delegate :name, to: :company, prefix: true
delegate :name, to: :entity, prefix: true, allow_nil: true
end
class Professional
include Mongoid::Document
include Mongoid::Timestamps
include SimpleEnum::Mongoid
include Likeable
include UserProfile
...
belongs_to :user
...
到std::chrono::minutes
),std::chrono::hours
将如何转换?例如,如果转换为duration_cast
,std::chrono::minutes(91)
会变成什么值? 2小时,1小时?
答案 0 :(得分:7)
duration_cast
总是向零舍入。即正值向下舍入,负值向上舍入。
有关其他舍入选项,请参阅:
http://howardhinnant.github.io/duration_io/chrono_util.html
floor
,ceil
和round
目前正在草案C ++ 1z(希望是C ++ 17)草案工作文件中。在此期间,您可以随意使用chrono_util.html处的代码,如果您有任何问题,请与我们联系。
std::chrono::floor<std::chrono::seconds>(1400ms) == 1s
std::chrono::floor<std::chrono::seconds>(1500ms) == 1s
std::chrono::floor<std::chrono::seconds>(1600ms) == 1s
std::chrono::floor<std::chrono::seconds>(-1400ms) == -2s
std::chrono::floor<std::chrono::seconds>(-1500ms) == -2s
std::chrono::floor<std::chrono::seconds>(-1600ms) == -2s