html/binary_time.pl
1 ###
2 #
3 # binary_time.pl
4 #
5 # Description:
6 # This script prints the timestamp in binary as follows:
7 # 09:25 would be 01001:011001
8 # 23:49 would be 10111:110001
9 #
10 # Bugs:
11 # If there are any bugs, please email me at aaron.toponce@gmail.com, and I'll get to them as I can.
12 # Please provide the irrsi version that you are using when the bug occurred, as well as a thorough
13 # description of how you noticed the bug. This means providing details of other scripts that you
14 # are using including themes. Please be as detailed as possible. It is my attempt to recreate the
15 # bug. I make no assurance that I will fix the bug, but I will make my best attempt at locating it.
16 #
17 # Contact:
18 # IRC: #irssi on freenode
19 # Email: aaron.toponce@gmail.com
20 # Jabber: aaron.toponce@gmail.com
21 #
22 # Change release:
23 # - 20060826 : Initial release
24 ###
25
26 use Irssi;
27 use strict;
28
29 use vars qw($VERSION %IRSSI);
30
31 $VERSION="20060826";
32 %IRSSI = (
33 authors => 'Aaron Toponce, Knut Auvor Grythe',
34 contact => 'aaron.toponce@gmail.com, irssi@auvor.no',
35 name => 'binary_time',
36 description => 'Prints the timestamp in binary format',
37 license => 'GPL',
38 );
39
40 my $old_timestamp_format = Irssi::settings_get_str('timestamp_format');
41
42 sub hour2bin {
43 my $str = unpack("B32", pack("N", shift));
44 $str =~ s/^0{27}(?=\d)//; # remove unecessary leading zeros (we only need 5 digits for the hour)
45 return $str;
46 }
47
48 sub min2bin {
49 my $str = unpack("B32", pack("N", shift));
50 $str =~ s/^0{26}(?=\d)//; # remove unecessary leading zeros (we only need 6 digits for the minute)
51 return $str;
52 }
53
54 sub convert_to_binary
55 {
56 # Get the hour and minute from the localtime on the users machine.
57 my $hour = (localtime)[2];
58 my $minute = (localtime)[1];
59
60 my $new_time = hour2bin($hour) . "." . min2bin($minute);
61 Irssi::command("^set timestamp_format $new_time");
62 }
63
64 sub script_unload {
65 my ($script,$server,$witem) = @_;
66 Irssi::command("^set timestamp_format $old_timestamp_format");
67 }
68
69 Irssi::timeout_add(1000, 'convert_to_binary', undef);
70 Irssi::signal_add_first('command script unload', 'script_unload');