Skip to content

Commit

Permalink
Timestamp plugin issue 15 (#31)
Browse files Browse the repository at this point in the history
* This plugin prints a timestamp in your commit message.

* This plugin prints a timestamp in your commit message.

* This plugin works well. It might be better if it were case insensitive.

* User can use 'utc' or 'UTC' in configuration file
  • Loading branch information
ianpaul authored and cmdln committed Aug 22, 2017
1 parent 4ea2dca commit 4e26ba8
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/flashbake/plugins/timestamp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2017 Ian Paul
# Copyright 2009 Thomas Gideon
#
# This file is part of flashbake.
#
# flashbake 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 3 of the License, or
# (at your option) any later version.
#
# flashbake 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 flashbake. If not, see <http://www.gnu.org/licenses/>.

''' timestamp.py displays the timestamp for a current commit in local or UTC time using a 12- or 24-hour clock.
thanks to @carlosalonso (on GitHub) for the suggestion. '''

from flashbake.plugins import AbstractMessagePlugin
from flashbake.plugins.timezone import findtimezone
import datetime


class Timestamp(AbstractMessagePlugin):
def __init__(self, plugin_spec):
AbstractMessagePlugin.__init__(self, plugin_spec, False)
self.define_property('time_format', required=False)
self.define_property('time_hours', required=False)

def addcontext(self, message_file, config):

''' Determine whether the timestamp is in local or UTC time, and whether it uses a 12- or 24-hour clock. '''

if self.time_format == 'utc' or 'UTC' and self.time_hours == '24':
zone = findtimezone(config)
message_file.write(str(datetime.datetime.utcnow().strftime('%A, %B %d, %Y %H:%M UTC in ') + str(zone) + '\n'))
elif self.time_format == 'utc' or 'UTC' and self.time_hours == '12':
zone = findtimezone(config)
message_file.write(str(datetime.datetime.utcnow().strftime('%A, %B %d, %Y %I:%M %p UTC in ') + str(zone) + '\n'))
elif self.time_format == 'local' and self.time_hours == '24':
zone = findtimezone(config)
message_file.write(str(datetime.datetime.now().strftime('%A, %B %d, %Y %H:%M in ') + str(zone) + '\n'))
elif self.time_format == 'local' and self.time_hours == '12':
zone = findtimezone(config)
message_file.write(str(datetime.datetime.now().strftime('%A, %B %d, %Y %I:%M %p in ') + str(zone) + '\n'))
else:
message_file.write('Time format could not be determined. Please specify UTC or local time, and a 12- or 24-hour clock in your configuration file. \n')

0 comments on commit 4e26ba8

Please sign in to comment.