我想在orderDatetime字段中创建跟随日期时间的completedDatetime。
Fixtures.yml
directive_{200..500}:
orderDatetime: <dateTimeThisYear()>
completedDatetime: '90%? <dateTimeBetween("orderDatetime", "now")>'
我在我的fixtures文件中使用了上面的代码并得到了随后的数据。
有没有办法确保使用faker数据而不是在LoadFixtures中编写自定义函数来获得理智的结果?
答案 0 :(得分:0)
由于您将字符串“orderDatetime”传递给 DECLARE @previous DATETIME = CAST(DATEADD(DAY,
( DATEDIFF(DAY,
( DATEADD(DAY, 0,
GETDATE()) ),
( DATEADD(MONTH,
-1,
CONVERT(DATETIME, CAST(YEAR(GETDATE()) AS VARCHAR)
+ '/'
+ CAST(MONTH(GETDATE()) AS VARCHAR)
+ '/' + '19', 102)) )) ),
GETDATE()) AS DATE)
DECLARE @current DATETIME = CAST(DATEADD(DAY,
( DATEDIFF(DAY,
( DATEADD(DAY, 0,
GETDATE()) ),
( DATEADD(MONTH,
0,
CONVERT(DATETIME, CAST(YEAR(GETDATE()) AS VARCHAR)
+ '/'
+ CAST(MONTH(GETDATE()) AS VARCHAR)
+ '/' + '20', 102)) )) ),
GETDATE()) AS DATE)
SELECT [Date],
Branch ,
Attendance
FROM ( SELECT CONVERT(VARCHAR, Date, 103) AS [Date] ,
Branch ,
Attendance
FROM Table_attd
) T
WHERE ( t.Date >= @previous
AND t.Date <= @current
)
函数,因此它返回1970年,而您的strtotime()
就像dateTimeBetween
一样。使用dateTimeBetween('1970', 'now')
完成变量的传递。但是如果将这样的变量传递给$orderDatetime
,则未来的dateTime可能会被传递,这是不可能的。
仅当您的订单日期是从现在起的过去时才有效:
dateTimeBetween()
如果您想要生成未来日期,则需要创建自定义faker功能,例如:
orderDatetime: '<dateTimeBetween("-200 days", "now")>'
completedDatetime: '90%? <dateTimeBetween($orderDatetime, "now")>'
并像这样使用它:
public function dateTimeBetweenAfter($dateFrom, $dateTo)
{
$date = new DateTime($dateFrom->format('Y-m-d H:i:s'));
$dateTo = $date->modify($dateTo);
return FakerDateTime::dateTimeBetween($dateFrom, $dateTo);
}