PageRenderTime 774ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/macros/Text/Insert_Date.bsh

#
Unknown | 80 lines | 67 code | 13 blank | 0 comment | 0 complexity | 02474a492216b0e9fb77079984ed494a MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * Insert_Date.bsh - a BeanShell macro script for the
  3. * jEdit text editor - insert current date and "Internet Time"
  4. * at current caret position
  5. * Copyright (C) 2001 John Gellene (on behalf of author)
  6. * jgellene@nyc.rr.com
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with the jEdit program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. *
  22. * $Id: Insert_Date.bsh 3866 2001-11-06 15:04:21Z jgellene $
  23. *
  24. * Checked for jEdit 4.0 API
  25. *
  26. */
  27. // Inserts the current date and Internet Time at the caret position
  28. // "Internet Time" is a new and easy way to measure time across the world
  29. // To find more "Internet Time"-related information go to
  30. // http://www.swatch.com/alu_beat/fs_itime.html
  31. // Wed Jan 31 03:12:33 AKST 2001 @550 /Internet Time/
  32. void insertDate()
  33. {
  34. Calendar rightNow = Calendar.getInstance();
  35. // zone offset with daylight savings
  36. int zoffset = (rightNow.get(Calendar.ZONE_OFFSET) +
  37. rightNow.get(Calendar.DST_OFFSET)) / 60000;
  38. // parsing current hour, minute and second
  39. double h = rightNow.get(Calendar.HOUR_OF_DAY);
  40. double m = rightNow.get(Calendar.MINUTE);
  41. double s = rightNow.get(Calendar.SECOND);
  42. // calculating internet time
  43. double swatch = Math.floor
  44. ((h * 3600 + ((m - zoffset + 60) * 60) + s) * 1000 / 86400);
  45. if (swatch >= 1000)
  46. swatch -= 1000;
  47. else if (swatch < 0)
  48. swatch += 1000;
  49. // inserting date and internet time to textarea
  50. textArea.setSelectedText(Calendar.getInstance().getTime().toString()
  51. + " @" + (int)swatch + " /Internet Time/");
  52. }
  53. insertDate();
  54. /*
  55. Macro index data (in DocBook format)
  56. <listitem>
  57. <para><filename>Insert_Date.bsh</filename></para>
  58. <abstract><para>
  59. Inserts the current date and time in the current buffer.
  60. </para></abstract>
  61. <para>
  62. The inserted text includes a representation of the time in the
  63. <quote>Internet Time</quote> format.
  64. </para>
  65. </listitem>
  66. */
  67. // end Insert_Date.bsh