How to use the humanize.naturaldate 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_naturaldate(test_input, expected):
    assert humanize.naturaldate(test_input) == expected
github containers / podman / contrib / python / pypodman / pypodman / lib / actions / images_action.py View on Github external
def list(self):
        """List images."""
        images = sorted(
            self.client.images.list(),
            key=operator.attrgetter(self._args.sort))
        if not images:
            return

        rows = list()
        for image in images:
            fields = dict(image)
            fields.update({
                'created':
                humanize.naturaldate(podman.datetime_parse(image.created)),
                'size':
                humanize.naturalsize(int(image.size)),
                'repoDigests':
                ' '.join(image.repoDigests),
            })

            for r in image.repoTags:
                name, tag = r.rsplit(':', 1)
                fields.update({
                    'name': name,
                    'tag': tag,
                })
            rows.append(fields)

        if not self._args.digests:
            del self.columns['repoDigests']
github containers / podman / contrib / python / pypodman / pypodman / lib / actions / ps_action.py View on Github external
lambda c: podman.FoldedString(c['status']) == 'running',
                self.client.containers.list())

        # TODO: Verify sorting on dates and size
        ctnrs = sorted(ictnrs, key=operator.attrgetter(self._args.sort))
        if not ctnrs:
            return

        rows = list()
        for ctnr in ctnrs:
            fields = dict(ctnr)
            fields.update({
                'command':
                ' '.join(ctnr.command),
                'createdat':
                humanize.naturaldate(podman.datetime_parse(ctnr.createdat)),
            })
            rows.append(fields)

        with Report(self.columns, heading=self._args.heading) as report:
            report.layout(
                rows, self.columns.keys(), truncate=self._args.truncate)
            for row in rows:
                report.row(**row)
github timofurrer / maya / src / maya / core.py View on Github external
def _translate(dt, target_locale):
    en = default_loader.get_locale("en")
    target = default_loader.get_locale(target_locale)
    naturaldate = humanize.naturaldate(dt)

    base = en.translate(naturaldate, settings=dateparser.conf.settings)

    return target.info["relative-type"][base][-1]
github containers / podman / contrib / python / pypodman / pypodman / lib / actions / history_action.py View on Github external
def history(self):
        """Report image history."""
        rows = list()
        for ident in self._args.image:
            for details in self.client.images.get(ident).history():
                fields = dict(details._asdict())

                if self._args.human:
                    fields.update({
                        'size':
                        humanize.naturalsize(details.size),
                        'created':
                        humanize.naturaldate(
                            podman.datetime_parse(details.created)),
                    })
                del fields['tags']

                rows.append(fields)

        if self._args.quiet:
            for row in rows:
                ident = row['id'][:12] if self._args.truncate else row['id']
                print(ident)
        elif self._args.format == 'json':
            print(json.dumps(rows, indent=2), flush=True)
        else:
            with Report(self.columns, heading=self._args.heading) as report:
                report.layout(
                    rows, self.columns.keys(), truncate=self._args.truncate)
github canonical-web-and-design / snapcraft.io / webapp / store / views.py View on Github external
'prices': details['snap']['prices'],
            'contact': details['snap'].get('contact'),
            'website': details['snap'].get('website'),
            'summary': details['snap']['summary'],
            'description_paragraphs': formatted_paragraphs,
            'channel_map': channel_maps_list,
            'has_stable': logic.has_stable(channel_maps_list),
            'developer_validation': details['snap']['publisher']['validation'],
            'default_track': default_track,
            'lowest_risk_available': lowest_risk_available,
            'confinement': confinement,

            # Transformed API data
            'filesize': humanize.naturalsize(binary_filesize),
            'last_updated': (
                humanize.naturaldate(
                    parser.parse(last_updated)
                )
            ),
            'last_updated_raw': last_updated,

            # Data from metrics API
            'countries': (
                country_devices.country_data if country_devices else None
            ),
            'normalized_os': os_metrics.os if os_metrics else None,

            # Context info
            'is_linux': (
                'Linux' in flask.request.headers.get('User-Agent', '') and
                'Android' not in flask.request.headers.get('User-Agent', '')
            ),
github gil9red / SimplePyScripts / humanize__examples / date_and_time__humanization.py View on Github external
# Date & time humanization:
import datetime as DT
print(humanize.naturalday(DT.datetime.now()))                         # 'today'
print(humanize.naturalday(DT.datetime.now() - DT.timedelta(days=1)))  # 'yesterday'
print(humanize.naturalday(DT.date(2007, 6, 5)))                       # 'Jun 05'
print()

print(DT.timedelta(seconds=1001))                         # '0:16:41'
print(humanize.naturaldelta(DT.timedelta(seconds=1001)))  # '16 minutes'
print(humanize.naturaldelta(DT.timedelta(seconds=5)))     # '5 seconds'
print(humanize.naturaldelta(DT.timedelta(hours=30)))      # 'a day'
print(humanize.naturaldelta(DT.timedelta(hours=60)))      # '2 days'
print()

print(humanize.naturaldate(DT.date(2007, 6, 5)))  # 'Jun 05 2007'
print(humanize.naturaldate(DT.date(2007, 6, 5)))  # 'Jun 05 2007'
print()

print(humanize.naturaltime(DT.datetime.now() - DT.timedelta(seconds=1)))     # 'a second ago'
print(humanize.naturaltime(DT.datetime.now() - DT.timedelta(seconds=3600)))  # 'an hour ago'
print(humanize.naturaltime(DT.datetime.now() - DT.timedelta(hours=30)))      # 'a day ago'