PageRenderTime 55ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Unknown | 80 lines | 67 code | 13 blank | 0 comment | 0 complexity | 5a3d9adc76d4ff2cff8a56fdd7750bda 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 4988 2004-03-08 04:29:12Z spestov $
  23. */
  24. // Inserts the current date and Internet Time at the caret position
  25. // "Internet Time" is a new and easy way to measure time across the world
  26. // To find more "Internet Time"-related information go to
  27. // http://www.swatch.com/alu_beat/fs_itime.html
  28. // Wed Jan 31 03:12:33 AKST 2001 @550 /Internet Time/
  29. void insertDate()
  30. {
  31. Calendar rightNow = Calendar.getInstance();
  32. // zone offset with daylight savings
  33. int zoffset = (rightNow.get(Calendar.ZONE_OFFSET) +
  34. rightNow.get(Calendar.DST_OFFSET)) / 60000;
  35. // parsing current hour, minute and second
  36. double h = rightNow.get(Calendar.HOUR_OF_DAY);
  37. double m = rightNow.get(Calendar.MINUTE);
  38. double s = rightNow.get(Calendar.SECOND);
  39. // calculating internet time
  40. double swatch = Math.floor
  41. ((h * 3600 + ((m - zoffset + 60) * 60) + s) * 1000 / 86400);
  42. if (swatch >= 1000)
  43. swatch -= 1000;
  44. else if (swatch < 0)
  45. swatch += 1000;
  46. // inserting date and internet time to textarea
  47. textArea.setSelectedText(Calendar.getInstance().getTime().toString()
  48. + " @" + (int)swatch + " /Internet Time/");
  49. }
  50. if(buffer.isReadOnly())
  51. Macros.error(view, "Buffer is read-only.");
  52. else
  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