time.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * BURG - Brand-new Universal loadeR from GRUB
  3. * Copyright 2010 Bean Lee - All Rights Reserved
  4. *
  5. * BURG is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * BURG is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with BURG. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <grub/dl.h>
  19. #include <grub/err.h>
  20. #include <grub/misc.h>
  21. #include <grub/datetime.h>
  22. #include <grub/command.h>
  23. #include <grub/i18n.h>
  24. static grub_err_t
  25. grub_cmd_time (grub_command_t cmd __attribute__ ((unused)),
  26. int argc, char **args)
  27. {
  28. struct grub_datetime t1, t2;
  29. int delta;
  30. grub_err_t err;
  31. if (argc < 1)
  32. grub_error (GRUB_ERR_BAD_ARGUMENT, "no command");
  33. if (grub_get_datetime (&t1))
  34. return grub_errno;
  35. err = grub_command_execute (args[0], argc - 1, args + 1);
  36. if (grub_get_datetime (&t2))
  37. return grub_errno;
  38. delta = (int) t2.year - (int) t1.year;
  39. delta = delta * 365 + (int) t2.day - (int) t1.day;
  40. delta = delta * 24 + (int) t2.hour - (int) t1.hour;
  41. delta = delta * 60 + (int) t2.minute - (int) t1.minute;
  42. delta = delta * 60 + (int) t2.second - (int) t1.second;
  43. grub_printf ("%d seconds\n", delta);
  44. return err;
  45. }
  46. static grub_command_t cmd;
  47. GRUB_MOD_INIT(time)
  48. {
  49. cmd =
  50. grub_register_command ("time", grub_cmd_time,
  51. N_("COMMAND"),
  52. N_("Execute COMMAND and print run time."));
  53. }
  54. GRUB_MOD_FINI(time)
  55. {
  56. grub_unregister_command (cmd);
  57. }