Skip to content

Commit

Permalink
:CREATED: <timestamp> --> :CREATED: [timestamp]
Browse files Browse the repository at this point in the history
Signed-off-by: Armin Wieser <armin.wieser@gmail.com>
  • Loading branch information
awieser committed Dec 20, 2011
1 parent 8ba46f3 commit dea9c8b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion calendars/memacs_calendar.py
Expand Up @@ -4,11 +4,11 @@

import sys
import os
from common.orgproperty import OrgProperties
# needed to import common.*
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from common.memacs import Memacs
from common.orgformat import OrgFormat
from common.orgproperty import OrgProperties
import codecs
from urllib2 import urlopen, HTTPError, URLError
import logging
Expand Down
30 changes: 30 additions & 0 deletions common/orgformat.py
Expand Up @@ -41,6 +41,26 @@ def date(tuple_date, show_time=False):
return time.strftime("<%Y-%m-%d %a %H:%M:%S>", tuple_date)
else:
return time.strftime("<%Y-%m-%d %a>", tuple_date)

@staticmethod
def inactive_date(tuple_date, show_time=False):
"""
returns a date string in org format
i.e.: * [YYYY-MM-DD Sun]
* [YYYY-MM-DD Sun HH:MM]
@param tuple_date: has to be a time.struct_time
@param show_time: optional show time also
"""
# <YYYY-MM-DD hh:mm>
assert tuple_date.__class__ == time.struct_time

if show_time:
if tuple_date.tm_sec == 0:
return time.strftime("[%Y-%m-%d %a %H:%M]", tuple_date)
else:
return time.strftime("[%Y-%m-%d %a %H:%M:%S]", tuple_date)
else:
return time.strftime("[%Y-%m-%d %a]", tuple_date)

@staticmethod
def datetime(tuple_datetime):
Expand All @@ -51,6 +71,16 @@ def datetime(tuple_datetime):
@param tuple_datetime has to be a time.struct_time
"""
return OrgFormat.date(tuple_datetime, show_time=True)

@staticmethod
def inactive_datetime(tuple_datetime):
"""
returns a date+time string in org format
wrapper for OrgFormat.inactive_date(show_time=True)
@param tuple_datetime has to be a time.struct_time
"""
return OrgFormat.inactive_date(tuple_datetime, show_time=True)

@staticmethod
def daterange(begin, end):
Expand Down
2 changes: 1 addition & 1 deletion common/orgproperty.py
Expand Up @@ -60,7 +60,7 @@ def __unicode__(self):
"""
if not self.__has_property("CREATED"):
self.add(OrgProperty("CREATED",
OrgFormat.datetime(time.localtime())))
OrgFormat.inactive_datetime(time.localtime())))
ret = unicode(OrgProperty("PROPERTIES"))
for p in self.__properties:
ret += unicode(p)
Expand Down
11 changes: 11 additions & 0 deletions common/tests/orgformat_test.py
Expand Up @@ -39,6 +39,17 @@ def test_date(self):
datetime = OrgFormat.date(t, show_time=True)
self.assertEqual("<2011-11-02 Wed>", date, "date error")
self.assertEqual("<2011-11-02 Wed 20:38>", datetime, "datetime error")

def test_inactive_date(self):
"""
test Org inactive_date
"""
# testing tuples
t = time.strptime("2011-11-02T20:38", "%Y-%m-%dT%H:%M")
date = OrgFormat.inactive_date(t)
datetime = OrgFormat.inactive_datetime(t)
self.assertEqual("[2011-11-02 Wed]", date, "date error")
self.assertEqual("[2011-11-02 Wed 20:38]", datetime, "datetime error")

def test_strings(self):
# testing strings
Expand Down

0 comments on commit dea9c8b

Please sign in to comment.