How to use the humanize.naturaldelta function in humanize

To help you get started, we’ve selected a few humanize 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 jmoiron / humanize / tests / test_time.py View on Github external
def test_naturaldelta_minimum_unit_explicit(minimum_unit, seconds, expected):
    # Arrange
    delta = dt.timedelta(seconds=seconds)

    # Act / Assert
    assert humanize.naturaldelta(delta, minimum_unit=minimum_unit) == expected
github jmoiron / humanize / tests / test_time.py View on Github external
def nd_nomonths(d):
    return humanize.naturaldelta(d, months=False)
github LNIS-Projects / OpenFPGA / openfpga_flow / scripts / run_fpga_task.py View on Github external
if args.show_thread_logs:
                        strip_child_logger_info(line[:-1])
                    sys.stdout.buffer.flush()
                    output.write(line)
                process.wait()
                if process.returncode:
                    raise subprocess.CalledProcessError(0, " ".join(command))
                eachJob["status"] = True
        except:
            logger.exception("Failed to execute openfpga flow - " +
                             eachJob["name"])
            if not args.continue_on_fail:
                os._exit(1)
        eachJob["endtime"] = time.time()
        timediff = timedelta(seconds=(eachJob["endtime"]-eachJob["starttime"]))
        timestr = humanize.naturaldelta(timediff) if "humanize" in sys.modules \
            else str(timediff)
        logger.info("%s Finished with returncode %d, Time Taken %s " %
                    (thread_name, process.returncode, timestr))
        eachJob["finished"] = True
        no_of_finished_job = sum([not eachJ["finished"] for eachJ in job_list])
        logger.info("***** %d runs pending *****" % (no_of_finished_job))
github SimonWoodburyForget / mindustry-mods / scripts / caching / __init__.py View on Github external
def delta_ago(self):
        dt = datetime.utcnow() - self.date
        return humanize.naturaldelta(dt)
github alexheretic / apart-gtk / src / running_job.py View on Github external
def update_remaining(self):
        if self.last_message.get('estimated_finish'):
            estimated_remaining = self.last_message['estimated_finish'] - datetime.now(timezone.utc)
            if estimated_remaining < timedelta(seconds=5):
                estimated_remaining_str = 'a few seconds'
            else:
                estimated_remaining_str = humanize.naturaldelta(estimated_remaining)
            self.estimated_completion.value_label.set_text(estimated_remaining_str)
            self.estimated_completion.show_all()
github eyaltrabelsi / pandas-log / pandas_log / timer.py View on Github external
def get_humanized_exec_time(end, start):
        """ Return the time it took a function to run in a human friendly way

            :param end: time exactly after method was applied
            :param start: time right before method was applied
            :return: execution time in human friendly way
        """

        exec_time = end - start
        exec_time_humanize = humanize.naturaldelta(exec_time)
        if exec_time_humanize == "a moment":
            exec_time_humanize = f"{exec_time} seconds."
        return f"\t* Step Took {exec_time_humanize}"
github b1naryth1ef / rowboat / rowboat / plugins / core.py View on Github external
    @Plugin.command('uptime', level=-1)
    def command_uptime(self, event):
        event.msg.reply('Rowboat was started {}'.format(
            humanize.naturaldelta(datetime.utcnow() - self.startup)
        ))
github tskit-dev / tsinfer / tsinfer / cli.py View on Github external
def summarise_usage():
    wall_time = humanize.naturaldelta(time.time() - __before)
    user_time = humanize.naturaldelta(os.times().user)
    sys_time = os.times().system
    if resource is None:
        # Don't report max memory on Windows. We could do this using the psutil lib, via
        # psutil.Process(os.getpid()).get_ext_memory_info().peak_wset if demand exists
        maxmem_str = ""
    else:
        max_mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
        if sys.platform != "darwin":
            max_mem *= 1024  # Linux and other OSs (e.g. freeBSD) report maxrss in kb
        maxmem_str = "; max memory={}".format(
            humanize.naturalsize(max_mem, binary=True)
        )
    logger.info("wall time = {}".format(wall_time))
    logger.info("rusage: user={}; sys={:.2f}s".format(user_time, sys_time) + maxmem_str)
github terbo / sigmon / app / sigmon.py View on Github external
def deltafy(ts):
  return humanize.naturaldelta(ts)
github fraschetti / Octoslack / octoprint_Octoslack / __init__.py View on Github external
def format_duration(self, seconds):
        time_format = self._settings.get(["time_format"], merged=True)
        if seconds == None:
            return "N/A"

        delta = datetime.timedelta(seconds=seconds)

        time_format = self._settings.get(["time_format"], merged=True)
        if time_format == "FUZZY":
            return humanize.naturaldelta(delta)
        elif time_format == "EXACT":
            return octoprint.util.get_formatted_timedelta(delta)
        else:
            return self.humanize_duration(seconds)