Skip to content

Commit 2a6efff

Browse files
committed
printformats learns to print current date and time
1 parent f5f1235 commit 2a6efff

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

khal/cli.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,22 @@ def printcalendars(ctx, include_calendar, exclude_calendar):
400400

401401
@cli.command()
402402
@click.pass_context
403-
def printformats(ctx):
403+
@click.option(
404+
'--now',
405+
help=('Print the current date and time in the local timezone instead.'),
406+
is_flag=True,
407+
)
408+
def printformats(ctx, now: bool):
404409
'''Print a date in all formats.
405410
406411
Print the date 2013-12-21 21:45 in all configured date(time)
407412
formats to check if these locale settings are configured to ones
408413
liking.'''
409414
time = dt.datetime(2013, 12, 21, 21, 45)
415+
if now:
416+
import pytz
417+
time = dt.datetime.utcnow()
418+
time = pytz.UTC.localize(time).astimezone(ctx.obj['conf']['locale']['local_timezone'])
410419
try:
411420
for strftime_format in [
412421
'longdatetimeformat', 'datetimeformat', 'longdateformat',
@@ -567,3 +576,4 @@ def configure(ctx):
567576

568577

569578
main_khal, main_ikhal = cli, interactive_cli
579+

0 commit comments

Comments
 (0)