bahai-date-api.js 844 B

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