bahai-date-api.js 847 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env node
  2. 'use strict';
  3. const {join} = require('path');
  4. const {cliBasics} = require('command-line-basics');
  5. const {
  6. getDate, getTodayJSON
  7. } = require('../api/controllers/bDateController.js');
  8. const optionDefinitions = cliBasics(
  9. join(__dirname, './optionDefinitions.js')
  10. );
  11. if (!optionDefinitions) { // cliBasics handled
  12. process.exit(); // eslint-disable-line no-process-exit
  13. }
  14. const {date, verbose} = optionDefinitions;
  15. let dateObj;
  16. if (date) {
  17. const dte = new Date(date);
  18. dateObj = getDate({
  19. year: dte.getFullYear(),
  20. month: dte.getMonth(),
  21. day: dte.getDate(),
  22. hour: dte.getHours(),
  23. minute: dte.getMinutes(),
  24. second: dte.getSeconds()
  25. });
  26. } else {
  27. dateObj = getTodayJSON();
  28. }
  29. const output = verbose ? dateObj : dateObj.json.message;
  30. // eslint-disable-next-line no-console
  31. console.log(output);