UNPKG

daniel-san

Version:

a node-based budget-projection engine that helps your routines and finances find balance. The program features aggregates, terminal and file-based reporting output, multi-currency conversion capability and multi-frequency accounting triggers, including: o

63 lines (47 loc) 1.89 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); var _require = require('../constants'), DATE_FORMAT_STRING = _require.DATE_FORMAT_STRING, DAILY = _require.DAILY, DATE_DELIMITER = _require.DATE_DELIMITER, ANNUALLY = _require.ANNUALLY, MONTHLY = _require.MONTHLY, WEEKLY = _require.WEEKLY, ONCE = _require.ONCE; /* function: getRelevantDateSegmentByFrequency description: returns the relevant part of the date. example: for WEEKLY frequency it only needs to return the weekday (as a number 0-6). for ANNUAL frequency it returns something like "12-31" */ var getRelevantDateSegmentByFrequency = function getRelevantDateSegmentByFrequency(_ref) { var frequency = _ref.frequency, date = _ref.date; var currentDateString = date.format(DATE_FORMAT_STRING); var _currentDateString$sp = currentDateString.split(DATE_DELIMITER), _currentDateString$sp2 = (0, _slicedToArray2["default"])(_currentDateString$sp, 3), currentYearString = _currentDateString$sp2[0], currentMonthString = _currentDateString$sp2[1], currentDayString = _currentDateString$sp2[2]; var currentWeekday = date.day(); switch (frequency) { case ANNUALLY: return "".concat(currentMonthString).concat(DATE_DELIMITER).concat(currentDayString); case MONTHLY: return currentDayString; case WEEKLY: return currentWeekday; case DAILY: break; case ONCE: return "".concat(currentYearString).concat(DATE_DELIMITER).concat(currentMonthString).concat(DATE_DELIMITER).concat(currentDayString); default: break; } }; module.exports = { getRelevantDateSegmentByFrequency: getRelevantDateSegmentByFrequency };