Files
odoo_source/addons/spreadsheet/static/tests/utils/date_domain.js
T
Lucas Lefèvre a20032cc1c [MOV] spreadsheet: move module to community
The spreadsheet module is moved to the community version
for the upcoming spreadsheet dashboards

This module is the core engine of spreadsheets in Odoo.
It contains `o-spreadsheet` library (o_spreadsheet.js) and all basic
integrations with odoo such as accounting formulas, lists, pivot, filters, etc.

This module alone does not have any action or menu to open a spreadsheet.
Those actions come with `documents_spreadsheet` module or the upcoming
`spreadsheet_dashboard` module.

Task 2799682

Part-of: odoo/odoo#97606
2022-09-10 02:54:51 +02:00

53 lines
1.6 KiB
JavaScript

/** @odoo-module */
const { DateTime } = luxon;
import { Domain } from "@web/core/domain";
function getDateDomainBounds(domain) {
const startDateStr = domain[1][2];
const endDateStr = domain[2][2];
const isDateTime = startDateStr.includes(":");
if (isDateTime) {
const dateTimeFormat = "yyyy-MM-dd HH:mm:ss";
const start = DateTime.fromFormat(startDateStr, dateTimeFormat);
const end = DateTime.fromFormat(endDateStr, dateTimeFormat);
return { start, end };
}
const start = DateTime.fromISO(startDateStr);
const end = DateTime.fromISO(endDateStr);
const startIsIncluded = domain[1][1] === ">=";
const endIsIncluded = domain[2][1] === "<=";
return {
start: startIsIncluded ? start.startOf("day") : start.endOf("day"),
end: endIsIncluded ? end.endOf("day") : end.startOf("day"),
};
}
/**
* @param {object} assert
* @param {string} field
* @param {string} start
* @param {string} end
* @param {import("@web/core/domain").DomainRepr} domain
*/
export function assertDateDomainEqual(assert, field, start, end, domain) {
domain = new Domain(domain).toList();
assert.deepEqual(domain[0], "&");
assert.deepEqual(domain[1], [field, ">=", start]);
assert.deepEqual(domain[2], [field, "<=", end]);
}
/**
* @param {import("@web/core/domain").DomainRepr} domain
* @returns {number}
*/
export function getDateDomainDurationInDays(domain) {
domain = new Domain(domain).toList();
const bounds = getDateDomainBounds(domain);
const diff = bounds.end.diff(bounds.start, ["days"]);
return Math.round(diff.days);
}