|
|
|
@ -109,33 +109,28 @@ const sqlite3 = {
|
|
|
|
|
const unit = convertUnits(rawUnit, 'sqlite'); |
|
|
|
|
switch (unit) { |
|
|
|
|
case 'seconds': |
|
|
|
|
sql = `ROUND((JULIANDAY(${datetime_expr1}) - JULIANDAY(${datetime_expr2})) * 86400)`; |
|
|
|
|
sql = `(strftime('%s', ${datetime_expr1}) - strftime('%s', ${datetime_expr2}))`; |
|
|
|
|
break; |
|
|
|
|
case 'minutes': |
|
|
|
|
sql = `ROUND((JULIANDAY(${datetime_expr1}) - JULIANDAY(${datetime_expr2})) * 1440)`; |
|
|
|
|
sql = `(strftime('%s', ${datetime_expr1}) - strftime('%s', ${datetime_expr2})) / 60`; |
|
|
|
|
break; |
|
|
|
|
case 'hours': |
|
|
|
|
sql = `ROUND((JULIANDAY(${datetime_expr1}) - JULIANDAY(${datetime_expr2})) * 24)`; |
|
|
|
|
sql = `(strftime('%s', ${datetime_expr1}) - strftime('%s', ${datetime_expr2})) / 3600`; |
|
|
|
|
break; |
|
|
|
|
case 'milliseconds': |
|
|
|
|
sql = `ROUND((JULIANDAY(${datetime_expr1}) - JULIANDAY(${datetime_expr2})) * 86400000)`; |
|
|
|
|
sql = `(strftime('%s', ${datetime_expr1}) - strftime('%s', ${datetime_expr2})) * 1000`; |
|
|
|
|
break; |
|
|
|
|
case 'weeks': |
|
|
|
|
sql = `ROUND((JULIANDAY(${datetime_expr1}) - JULIANDAY(${datetime_expr2})) / 7)`; |
|
|
|
|
break; |
|
|
|
|
case 'months': |
|
|
|
|
sql = `(ROUND((JULIANDAY(${datetime_expr1}) - JULIANDAY(${datetime_expr2})) / 365))
|
|
|
|
|
* 12 + (ROUND((JULIANDAY(${datetime_expr1}) - JULIANDAY(${datetime_expr2})) / 365 / 12))`;
|
|
|
|
|
sql = `(strftime('%Y', ${datetime_expr1}) - strftime('%Y', ${datetime_expr2})) * 12 + (strftime('%m', ${datetime_expr1}) - strftime('%m', ${datetime_expr2})) `; |
|
|
|
|
break; |
|
|
|
|
case 'quarters': |
|
|
|
|
sql = ` |
|
|
|
|
ROUND((JULIANDAY(${datetime_expr1})) / 365 / 4) - |
|
|
|
|
ROUND((JULIANDAY(${datetime_expr2})) / 365 / 4) + |
|
|
|
|
(ROUND((JULIANDAY(${datetime_expr1}) - JULIANDAY(${datetime_expr2})) / 365)) * 4 |
|
|
|
|
`;
|
|
|
|
|
sql = `(strftime('%Y', ${datetime_expr1}) - strftime('%Y', ${datetime_expr2})) * 4 + (strftime('%m', ${datetime_expr1}) - strftime('%m', ${datetime_expr2})) / 3`; |
|
|
|
|
break; |
|
|
|
|
case 'years': |
|
|
|
|
sql = `ROUND((JULIANDAY(${datetime_expr1}) - JULIANDAY(${datetime_expr2})) / 365)`; |
|
|
|
|
sql = `strftime('%Y', ${datetime_expr1}) - strftime('%Y', ${datetime_expr2})`; |
|
|
|
|
break; |
|
|
|
|
case 'days': |
|
|
|
|
sql = `JULIANDAY(${datetime_expr1}) - JULIANDAY(${datetime_expr2})`; |
|
|
|
|