bahai-date-api.js 900 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env node
  2. import {dirname, join} from 'path';
  3. import {fileURLToPath} from 'url';
  4. import {cliBasics} from 'command-line-basics';
  5. import {
  6. getDate, getTodayJSON
  7. } from '../api/controllers/bDateController.js';
  8. const __dirname = dirname(fileURLToPath(import.meta.url));
  9. const optionDefinitions = await cliBasics(
  10. join(__dirname, './optionDefinitions.js')
  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);