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 23971 2015-08-08 19:37:35Z daleanson $
23 */
24
25// Inserts the current date and Internet Time at the caret position
26// "Internet Time" is a new and easy way to measure time across the world
27// To find more "Internet Time"-related information go to
28// http://www.swatch.com/alu_beat/fs_itime.html
29
30// Wed Jan 31 03:12:33 AKST 2001 @550 /Internet Time/
31
32// Localization
33final static String InternetTimeLabel = jEdit.getProperty("macro.rs.InsertDate.InternetTime.label", "Internet Time");
34final static String NotEditableMessage = jEdit.getProperty("macro.rs.general.ErrorNotEditableDialog.message", "Buffer is not editable");
35
36// Process
37void insertDate()
38{
39	Calendar rightNow = Calendar.getInstance();
40
41	// zone offset with daylight savings
42	int zoffset = (rightNow.get(Calendar.ZONE_OFFSET) +
43	rightNow.get(Calendar.DST_OFFSET)) / 60000;
44
45	// parsing current hour, minute and second
46	double h = rightNow.get(Calendar.HOUR_OF_DAY);
47	double m = rightNow.get(Calendar.MINUTE);
48	double s = rightNow.get(Calendar.SECOND);
49
50	// calculating internet time
51	double swatch = Math.floor
52	((h * 3600 + ((m - zoffset + 60) * 60) + s) * 1000 / 86400);
53	if (swatch >= 1000)
54		swatch -= 1000;
55	else if (swatch < 0)
56		swatch += 1000;
57
58	// inserting date and internet time to textarea
59	textArea.setSelectedText(Calendar.getInstance().getTime().toString()
60		+ " @" + (int)swatch + " /" + InternetTimeLabel + "/");
61}
62
63	insertDate();
64
65/*
66	Macro index data (in DocBook format)
67
68<listitem>
69    <para><filename>Insert_Date.bsh</filename></para>
70    <abstract><para>
71        Inserts the current date and time in the current buffer.
72    </para></abstract>
73    <para>
74        The inserted text includes a representation of the time in the
75        <quote>Internet Time</quote> format.
76    </para>
77</listitem>
78
79*/
80
81// end Insert_Date.bsh
82
83