How to use the memacs.lib.orgformat.OrgFormat.datetime function in memacs

To help you get started, we’ve selected a few memacs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github novoid / Memacs / memacs / filenametimestamps.py View on Github external
# don't handle emacs tmp files (file~)
        if file[-1:] == '~':
            return

        link = os.path.join(rootdir, file)
        logging.debug(link)

        if self._args.force_filedate_extraction:
            file_datetime = time.localtime(os.path.getmtime(link))

            if self._args.skip_filetime_extraction:
                logging.debug('force_filedate_extraction and skip_filetime_extraction: using date')
                orgdate = OrgFormat.date(file_datetime)
            else:
                logging.debug('force_filedate_extraction and not skip_filetime_extraction: using datetime')
                orgdate = OrgFormat.datetime(file_datetime)

            self.__write_file(file, link, orgdate)

        elif DATESTAMP_REGEX.match(file):
            logging.debug('DATESTAMP_REGEX matches; trying __parse_filename_iso_timestamp() ...')
            try:
                # we put this in a try block because:
                # if a timestamp is false i.e. 2011-14-19 or false time
                # we can handle those not easy with REGEX, therefore we have
                # an Exception TimestampParseException, which is thrown,
                # when strptime (parse from string to time tupel) fails
                orgdate = self.__parse_filename_iso_timestamp(file, link)
                self.__write_file(file, link, orgdate)
            except TimestampParseException:
                logging.debug('__parse_filename_iso_timestamp() caused an TimestampParseException')
                logging.warning("False date(time) in file: %s", link)
github novoid / Memacs / memacs / lib / orgformat.py View on Github external
assert deltahours.__class__ in (int, float)
        assert orgtime.__class__ == str

        # first time-stamp: range_components.groups(0)[0]
        # second time-stamp: range_components.groups(0)[10]
        range_components = re.match(
            OrgFormat.ORGMODE_TIMESTAMP_RANGE_REGEX, orgtime)

        if range_components:
            return OrgFormat.datetime(
                OrgFormat.orgmode_timestamp_to_datetime(
                    range_components.groups(0)[0]) +
                datetime.timedelta(0, 0, 0, 0, 0, deltahours)) + \
                "-" + \
                OrgFormat.datetime(
                    OrgFormat.orgmode_timestamp_to_datetime(
                        range_components.groups(0)[10]) +
                    datetime.timedelta(0, 0, 0, 0, 0, deltahours))
        else:
            return OrgFormat.datetime(OrgFormat.orgmode_timestamp_to_datetime(orgtime) +
                                      datetime.timedelta(0, 0, 0, 0, 0, deltahours))