def test_apply_timedelta_to_org_timestamp(self): self.assertEqual( OrgFormat.apply_timedelta_to_org_timestamp( '<2019-11-05 Tue 23:59>', 1), '<2019-11-06 Wed 00:59>') self.assertEqual( OrgFormat.apply_timedelta_to_org_timestamp( '<2019-11-06 Wed 00:59>', -1), '<2019-11-05 Tue 23:59>') self.assertEqual( OrgFormat.apply_timedelta_to_org_timestamp( '<2019-11-05 Tue 23:59>', 2.0), '<2019-11-06 Wed 01:59>') self.assertEqual( OrgFormat.apply_timedelta_to_org_timestamp( '<2019-11-06 Wed 00:59>', -2.0), '<2019-11-05 Tue 22:59>') self.assertEqual( OrgFormat.apply_timedelta_to_org_timestamp( '<2019-12-31 Tue 23:00>', 2.5), '<2020-01-01 Wed 01:30>') self.assertEqual( OrgFormat.apply_timedelta_to_org_timestamp( '<2020-01-01 Wed 01:30>', -2.5), '<2019-12-31 Tue 23:00>') self.assertEqual( OrgFormat.apply_timedelta_to_org_timestamp( '<2019-12-31 Tue 23:00>-<2019-12-31 Tue 23:30>', 2.5), '<2020-01-01 Wed 01:30>--<2020-01-01 Wed 02:00>') self.assertEqual( OrgFormat.apply_timedelta_to_org_timestamp( '<2020-01-01 Wed 01:30>--<2020-01-01 Wed 02:00>', -2.5), '<2019-12-31 Tue 23:00>--<2019-12-31 Tue 23:30>')
def write_org_subitem(self, timestamp, output, note="", properties=OrgProperties(), tags=None): """ Writes an org item line. i.e:** <timestamp> <output> :<tags>:\n :PROPERTIES: <properties> :ID: -generated id- :END: if an argument -a or --append is given, then a desicion regarding the :ID: is made if the item has to be written to file @param timestamp: str/unicode or False (for no time-stamp) @param output: st tar/unicode @param note: str/unicode @param tags: list of tags @param properties: OrgProperties object """ assert (not timestamp or timestamp.__class__ == str or timestamp.__class__ == str) assert tags.__class__ == list or tags == None if self.__append: ## for the append mode, the ID within properties is mandatory: assert properties.__class__ == OrgProperties else: ## when properties is None, the whole drawer is omitted: assert properties.__class__ == OrgProperties or not properties assert (output.__class__ == str or output.__class__ == str) assert (note.__class__ == str or note.__class__ == str) # count the entries we have written, if above our limit do not write if self.__number_entries and \ self.__entries_count == self.__number_entries: return else: self.__entries_count += 1 if tags == None: tags = [] if self.__autotag_dict != {}: self.__get_autotags(tags, output) ## fix time-stamps (if user wants to) if timestamp and self.__timestamp_delta: timestamp = OrgFormat.apply_timedelta_to_org_timestamp( timestamp, float(self.__timestamp_delta)) ## a bit of a hack to get inactive time-stamps: ## FIXXME: use OrgFormat method to generate inactive time-stamps in the first place and remove asserts if timestamp and self.__inactive_timestamps and timestamp[ 0] == '<' and timestamp[-1] == '>': # FIXXME: very stupid overwriting of active time-stamp # with inactive one when inactive option is used and # somehow an active time-stamp is delivered somehow: timestamp = '[' + timestamp[1:-1] + ']' if self.__append: self.__append_org_subitem(timestamp, output, note, properties, tags) else: self.__write_org_subitem(timestamp, output, note, properties, tags)