示例问题:
当关闭商店时收到订单时> ex。凌晨4点 我想将调度调度时间设置为商店开业的时间。
我的营业时间是9am,但是订单是在4am收到的。我想在9am处理订单。我该怎么办?
由于当前正在发生,它将在第二天处理。
这是我的代码:
var storeOpen = _storeScheduleService.IsStoreOpen(context.TaskParam.Customer.StoreId.Value, context.CapturedDateTime);
if (storeOpen.IsOpen && storeOpen.Schedule != null)
{
if (context.CapturedDateTime.TimeOfDay <= storeOpen.Schedule.Close)
{
context.FirstDay = context.CapturedDateTime.Date;
return;
}
}
//check next 3 days
for (int i = 1; i <=3; i++)
{
var cDate = context.CapturedDateTime.AddDays(i).Date;
var isStoreOpen = _storeScheduleService.IsStoreOpenForDate(context.TaskParam.Customer.StoreId.Value, cDate);
if (isStoreOpen)
{
context.FirstDay = cDate.Date;
return;
}
}
答案 0 :(得分:0)
DateTime today = DateTime.Today;
DateTime storeOpen = new DateTime(today.Year, today.Month, today.Day, 9, 0, 0);
var recievedOrderDate = DateTime.Now();
var resultOpen = DateTime.Compare(recievedOrderDate, storeOpen);
if (resultOpen < 0)
// Process order.
// You can also check and process the next day.
DateTime storeClosed = new DateTime(today.Year, today.Month, today.Day, 17, 0, 0);
var resultClose = DateTime.Compare(recievedOrderDate, storeClosed)
if (resultClose > 0)
// Process next day or whenever you want.
答案 1 :(得分:0)
使用此代码:
double diffindate = (DesireOrderDate - DateTime.Today).Value.TotalDays;
double diffintime = (DesireOrderTime - DateTime.Now.TimeOfDay).Value.TotalHours;
if (diffindate = 0 && diffintime = 0)
{
}