summaryrefslogtreecommitdiffstats
path: root/scripts/binary_time.pl
blob: 610ae11641f66a9d190a17f7f8bb6312c013719e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
###
#
# binary_time.pl
#
# Description: 
# This script prints the timestamp in binary as follows:
# 09:25 would be 01001:011001
# 23:49 would be 10111:110001
#
# Bugs:
# If there are any bugs, please email me at aaron.toponce@gmail.com, and I'll get to them as I can.
# Please provide the irrsi version that you are using when the bug occurred, as well as a thorough
# description of how you noticed the bug.  This means providing details of other scripts that you
# are using including themes.  Please be as detailed as possible.  It is my attempt to recreate the
# bug.  I make no assurance that I will fix the bug, but I will make my best attempt at locating it.
#
# Contact:
# 	IRC:    #irssi on freenode
# 	Email:  aaron.toponce@gmail.com
#	Jabber: aaron.toponce@gmail.com 
#
# Change release:
#	- 20060826 : Initial release
###

use Irssi;
use strict;

use vars qw($VERSION %IRSSI);

$VERSION="20060826";
%IRSSI = (
	authors		=> 'Aaron Toponce, Knut Auvor Grythe',
	contact		=> 'aaron.toponce@gmail.com, irssi@auvor.no',
	name		=> 'binary_time',
	description	=> 'Prints the timestamp in binary format',
	license		=> 'GPL',
);

my $old_timestamp_format = Irssi::settings_get_str('timestamp_format');

sub hour2bin {
	my $str = unpack("B32", pack("N", shift));
	$str =~ s/^0{27}(?=\d)//;   # remove unecessary leading zeros (we only need 5 digits for the hour)
	return $str;
}

sub min2bin {
	my $str = unpack("B32", pack("N", shift));
	$str =~ s/^0{26}(?=\d)//;   # remove unecessary leading zeros (we only need 6 digits for the minute)
	return $str;
}

sub convert_to_binary
{
	# Get the hour and minute from the localtime on the users machine.
	my $hour = (localtime)[2];
	my $minute = (localtime)[1];
	
	my $new_time = hour2bin($hour) . "." . min2bin($minute);
	Irssi::command("^set timestamp_format $new_time");
}

sub script_unload {
	my ($script,$server,$witem) = @_;
	Irssi::command("^set timestamp_format $old_timestamp_format");
}

Irssi::timeout_add(1000, 'convert_to_binary', undef);
Irssi::signal_add_first('command script unload', 'script_unload');