2008-08-15 19:31:51 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
2008-08-15 05:20:23 +02:00
|
|
|
## src/common/fuzzyclock.py
|
2006-06-15 09:18:55 +02:00
|
|
|
##
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2006 Christoph Neuroth <delmonico AT gmx.net>
|
2012-01-11 22:20:34 +01:00
|
|
|
## Copyright (C) 2006-2012 Yann Leboulanger <asterix AT lagaule.org>
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2007 Jean-Marie Traissard <jim AT lapin.org>
|
2009-09-07 20:23:35 +02:00
|
|
|
## Copyright (C) 2009 Benjamin Richter <br AT waldteufel-online.net>
|
2006-06-15 09:18:55 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2006-06-15 09:18:55 +02:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-10-22 13:13:13 +02:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2006-06-15 09:18:55 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2006-06-15 09:18:55 +02:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-08-15 05:20:23 +02:00
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2006-06-15 09:18:55 +02:00
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## You should have received a copy of the GNU General Public License
|
2008-08-15 05:20:23 +02:00
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-22 13:13:13 +02:00
|
|
|
##
|
2006-06-15 09:14:39 +02:00
|
|
|
|
2009-11-26 12:58:12 +01:00
|
|
|
"""
|
2006-06-15 09:14:39 +02:00
|
|
|
Python class to show a "fuzzy clock".
|
2009-09-07 20:23:35 +02:00
|
|
|
Homepage of the original: http://home.gna.org/fuzzyclock/
|
|
|
|
Project Page of the original: http://gna.org/projects/fuzzyclock
|
2006-06-15 09:14:39 +02:00
|
|
|
|
2009-09-07 20:23:35 +02:00
|
|
|
The class is based on a port from PHP code by
|
2006-06-15 09:14:39 +02:00
|
|
|
Henrique Recidive <henrique at recidive.com> which was
|
|
|
|
in turn based on the Fuzzy Clock Applet of Frerich Raabe (KDE).
|
|
|
|
So most of the credit goes to this guys, thanks :-)
|
2009-11-26 12:58:12 +01:00
|
|
|
"""
|
2006-06-15 09:14:39 +02:00
|
|
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
class FuzzyClock:
|
2010-02-08 15:08:40 +01:00
|
|
|
HOUR_NAMES = [ _('twelve'), _('one'), _('two'), _('three'), _('four'),
|
|
|
|
_('five'), _('six'), _('seven'), _('eight'), _('nine'), _('ten'),
|
|
|
|
_('eleven') ]
|
2007-02-04 19:57:25 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
#Strings to use for the output. %(0)s will be replaced with the preceding hour
|
|
|
|
#(e.g. "x PAST %(0)s"), %(1)s with the coming hour (e.g. "x TO %(0)s"). '''
|
|
|
|
FUZZY_TIME = [ _("%(0)s o'clock"), _('five past %(0)s'), _('ten past %(0)s'),
|
|
|
|
_('quarter past %(0)s'), _('twenty past %(0)s'), _('twenty five past %(0)s'),
|
|
|
|
_('half past %(0)s'), _('twenty five to %(1)s'), _('twenty to %(1)s'),
|
|
|
|
_('quarter to %(1)s'), _('ten to %(1)s'), _('five to %(1)s'), _("%(1)s o'clock") ]
|
2007-02-04 19:57:25 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
FUZZY_DAYTIME = [ _('Night'), _('Early morning'), _('Morning'),
|
|
|
|
_('Almost noon'), _('Noon'), _('Afternoon'), _('Evening'),
|
|
|
|
_('Late evening'), _('Night') ]
|
2007-02-04 19:57:25 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
FUZZY_WEEK = [ _('Start of week'), _('Middle of week'), _('Middle of week'),
|
|
|
|
_('Middle of week'), _('End of week'), _('Weekend!'), _('Weekend!') ]
|
2007-02-04 19:57:25 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def fuzzy_time(self, fuzzyness, now):
|
|
|
|
if fuzzyness == 1 or fuzzyness == 2:
|
|
|
|
if fuzzyness == 1:
|
|
|
|
sector = int(round(now.tm_min / 5.0))
|
|
|
|
else:
|
|
|
|
sector = int(round(now.tm_min / 15.0)) * 3
|
2007-02-04 19:57:25 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
return self.FUZZY_TIME[sector] % {
|
|
|
|
'0': self.HOUR_NAMES[now.tm_hour % 12],
|
|
|
|
'1': self.HOUR_NAMES[(now.tm_hour + 1) % 12]}
|
2007-02-04 19:57:25 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
elif fuzzyness == 3:
|
|
|
|
return self.FUZZY_DAYTIME[int(round(now.tm_hour / 3.0))]
|
2007-02-04 19:57:25 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
return self.FUZZY_WEEK[now.tm_wday]
|