#!/usr/bin/perl -w

#   DayStart - print date in all open tabs at midnight
#   Copyright (C) 2015  Jernej Simoncic
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
#
#Changelog:
#
#2015-06-14: first version

use strict;
use warnings;
use utf8;

sub daychange($$$)
{
	my ($day,$mon,$year) = @_;
	foreach my $tab (Xchat::get_list('channels')) {
		Xchat::set_context $tab->{context};
		Xchat::print "\0035┈┄\0034┄╌────╯ $day.$mon.$year ╰────────────────────────────────────────────────────────╌┄\0035┄┈";
	}
}

sub timer
{
	my ($sec,$min,$hour,$day,$mon,$year) = localtime(time);
	if ($sec <= 1 && $min == 0 && $hour == 0) {
		daychange($day,$mon,$year+1900);
		Xchat::hook_timer(86390000, \&timer);
	} else {
		$sec += $min*60 + $hour*3600;
		Xchat::hook_timer((86400 - $sec) * 1000, \&timer);
	}
	return Xchat::REMOVE;
}

Xchat::hook_timer(1000,\&timer);
