PageRenderTime 131ms CodeModel.GetById 128ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre5/macros/Text/Insert_Date.bsh

#
Unknown | 80 lines | 67 code | 13 blank | 0 comment | 0 complexity | 02474a492216b0e9fb77079984ed494a MD5 | raw file
 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
28// Inserts the current date and Internet Time at the caret position
29// "Internet Time" is a new and easy way to measure time across the world
30// To find more "Internet Time"-related information go to
31// http://www.swatch.com/alu_beat/fs_itime.html
32
33// Wed Jan 31 03:12:33 AKST 2001 @550 /Internet Time/
34
35void insertDate()
36{
37	Calendar rightNow = Calendar.getInstance();
38
39	// zone offset with daylight savings
40	int zoffset = (rightNow.get(Calendar.ZONE_OFFSET) +
41	rightNow.get(Calendar.DST_OFFSET)) / 60000;
42
43	// parsing current hour, minute and second
44	double h = rightNow.get(Calendar.HOUR_OF_DAY);
45	double m = rightNow.get(Calendar.MINUTE);
46	double s = rightNow.get(Calendar.SECOND);
47
48	// calculating internet time
49	double swatch = Math.floor
50	((h * 3600 + ((m - zoffset + 60) * 60) + s) * 1000 / 86400);
51	if (swatch >= 1000)
52		swatch -= 1000;
53	else if (swatch < 0)
54		swatch += 1000;
55
56	// inserting date and internet time to textarea
57	textArea.setSelectedText(Calendar.getInstance().getTime().toString()
58		+ " @" + (int)swatch + " /Internet Time/");
59}
60
61insertDate();
62
63/*
64	Macro index data (in DocBook format)
65
66<listitem>
67    <para><filename>Insert_Date.bsh</filename></para>
68    <abstract><para>
69        Inserts the current date and time in the current buffer.
70    </para></abstract>
71    <para>
72        The inserted text includes a representation of the time in the
73        <quote>Internet Time</quote> format.
74    </para>
75</listitem>
76
77*/
78
79// end Insert_Date.bsh
80