Versie 0.2.0
This commit is contained in:
commit
e77d8fd373
495 files changed
+81026
No files matched your search
@@ -0,0 +1,71 @@
|
||||
// Generated, do not edit. sha256:945ee26961af9e68d689f5dc6bc4e4b542606ba5501cbaee8b17b7df9349fba6
|
||||
import { CONFIG, ENUMS } from '../../shared/config.js';
|
||||
|
||||
export function assertEnum(name, list, value) {
|
||||
if (!list.includes(value)) {
|
||||
throw new Error(`Invalid ${name}: '${value}'. Allowed: ${list.join(', ')}.`);
|
||||
}
|
||||
}
|
||||
|
||||
export function assertTaxCategory(value) {
|
||||
if (value == null || value === '') return null;
|
||||
assertEnum('taxCategory', ENUMS.TAX_CATEGORY, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
export function assertTaxScope(value) {
|
||||
if (value == null || value === '') return null;
|
||||
assertEnum('taxScope', ENUMS.TAX_SCOPE, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
export function assertWealthScope(value) {
|
||||
if (value == null || value === '') return null;
|
||||
assertEnum('wealthScope', ENUMS.WEALTH_SCOPE, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
export const RATE_ONLY_ASSET = `(Asset.kind = 'fiat' AND Asset.symbol <> (SELECT baseCurrency FROM Portfolio)
|
||||
AND NOT EXISTS (SELECT 1 FROM Event WHERE Event.assetId = Asset.id)
|
||||
AND NOT EXISTS (SELECT 1 FROM Valuation WHERE Valuation.assetId = Asset.id)
|
||||
AND NOT EXISTS (SELECT 1 FROM InterestSchedule
|
||||
WHERE InterestSchedule.principalAssetId = Asset.id OR InterestSchedule.payoutAssetId = Asset.id))`;
|
||||
|
||||
export function nowIso() { return new Date().toISOString(); }
|
||||
|
||||
const TIMESTAMP = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.\d{1,6})?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/;
|
||||
|
||||
export function assertTimestamp(field, value) {
|
||||
const m = typeof value === 'string' ? value.match(TIMESTAMP) : null;
|
||||
if (!m) {
|
||||
throw new Error(`Invalid ${field}: '${value}'. A date is expected (2026-08-19), optionally with a time.`);
|
||||
}
|
||||
const [, jaar, maand, dag, uur = '0', minuut = '0', seconde = '0'] = m;
|
||||
const d = new Date(Date.UTC(Number(jaar), Number(maand) - 1, Number(dag)));
|
||||
const bestaat = d.getUTCFullYear() === Number(jaar)
|
||||
&& d.getUTCMonth() === Number(maand) - 1
|
||||
&& d.getUTCDate() === Number(dag);
|
||||
if (!bestaat) throw new Error(`Invalid ${field}: '${value}' is not an existing date.`);
|
||||
if (Number(uur) > 23 || Number(minuut) > 59 || Number(seconde) > 59) {
|
||||
throw new Error(`Invalid ${field}: '${value}' is not an existing time.`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function assertName(field, value) {
|
||||
const naam = typeof value === 'string' ? value.trim() : '';
|
||||
if (!naam) throw new Error(`${field} may not be empty.`);
|
||||
return naam;
|
||||
}
|
||||
|
||||
export function todayIso() {
|
||||
return new Date().toLocaleDateString('en-CA', { timeZone: CONFIG.PEILDATUM.TIMEZONE });
|
||||
}
|
||||
|
||||
export function daysBetween(aIso, bIso) { return (Date.parse(bIso) - Date.parse(aIso)) / 86400000; }
|
||||
|
||||
export function isoToDate(iso) { return new Date(`${iso}T00:00:00Z`); }
|
||||
export function dateToIso(d) { return d.toISOString().slice(0, 10); }
|
||||
export function addDaysIso(iso, n) { const d = isoToDate(iso); d.setUTCDate(d.getUTCDate() + n); return dateToIso(d); }
|
||||
export function weekdayOf(iso) { return isoToDate(iso).getUTCDay(); }
|
||||
export function clampDom(year, month0, dom) { const last = new Date(Date.UTC(year, month0 + 1, 0)).getUTCDate(); return Math.min(dom, last); }
|
||||
Reference in new issue
Block a user