Did I find the right examples for you? yes no

All Samples(10)  |  Call(8)  |  Derive(0)  |  Import(2)
Simmilar to django.utils.timesince.timesince, but:
    * display "X Sec" and "X ms", too
    * generates html code with both information
    
>>> timesince2(datetime.datetime(2005, 7, 14, 0), datetime.datetime(2005, 7, 16, 12))
u'<span title="July 14, 2005, midnight" style="cursor:help;">2.5 days</span>'

>>> timesince2(datetime.datetime(2005, 7, 14, 12, 30, 00), datetime.datetime(2005, 7, 14, 12, 30, 10))
u'<span title="July 14, 2005, 12:30 p.m." style="cursor:help;">10.0 sec</span>'
(more...)

        def timesince2(d, now=None):
    """
    Simmilar to django.utils.timesince.timesince, but:
        * display "X Sec" and "X ms", too
        * generates html code with both information
        
    >>> timesince2(datetime.datetime(2005, 7, 14, 0), datetime.datetime(2005, 7, 16, 12))
    u'2.5 days'
    
    >>> timesince2(datetime.datetime(2005, 7, 14, 12, 30, 00), datetime.datetime(2005, 7, 14, 12, 30, 10))
    u'10.0 sec'
    
    >>> timesince2(datetime.datetime(2005, 7, 14, 12, 30, 00), datetime.datetime(2005, 7, 14, 12, 30, 00, 1200))
    u'1.2 ms'
    """
    if not isinstance(d, datetime.datetime):
        # Convert datetime.date to datetime.datetime for comparison.
        d = datetime.datetime(d.year, d.month, d.day)

    if now is None:
        if d.tzinfo:
            now = datetime.datetime.now(LocalTimezone(d))
        else:
            now = datetime.datetime.now()
    elif not isinstance(now, datetime.datetime):
            # Convert datetime.date to datetime.datetime
            now = datetime.datetime(now.year, now.month, now.day)

    # ignore microsecond part of 'd' since we removed it from 'now'
    delta = now - (d - datetime.timedelta(0, 0, d.microsecond))

    result = human_duration(delta)

    context = {"d": d, "timesince": result}
    return render_to_string("django_processinfo/timesince.html", context)
        


src/d/j/django-processinfo-0.7.0/django_processinfo/admin.py   django-processinfo(Download)
from django_processinfo.models import SiteStatistics, ProcessInfo
from django_processinfo.utils.average import average
from django_processinfo.utils.human_time import timesince2, human_duration, \
    datetime2float
from django_processinfo.utils.proc_info import meminfo, uptime_infomation, \
    def start_time2(self, obj):
        return timesince2(obj.start_time)
    start_time2.short_description = _("start since")
    start_time2.admin_order_field = "start_time"
    start_time2.allow_tags = True
            "swap_total": swap_total,
 
            "updatetime": timesince2(updatetime),
 
            "script_filename": self.request.META.get("SCRIPT_FILENAME", "???"),
    def lastupdate_time2(self, obj):
        return timesince2(obj.lastupdate_time)
    lastupdate_time2.short_description = _("last update")
    lastupdate_time2.admin_order_field = "lastupdate_time"
    lastupdate_time2.allow_tags = True
 
    def life_time(self, obj):
        return timesince2(obj.start_time, obj.lastupdate_time)

src/d/j/django-processinfo-HEAD/django_processinfo/admin.py   django-processinfo(Download)
from django_processinfo.models import SiteStatistics, ProcessInfo
from django_processinfo.utils.average import average
from django_processinfo.utils.human_time import timesince2, human_duration, \
    datetime2float
from django_processinfo.utils.proc_info import meminfo, uptime_infomation, \
    def start_time2(self, obj):
        return timesince2(obj.start_time)
    start_time2.short_description = _("start since")
    start_time2.admin_order_field = "start_time"
    start_time2.allow_tags = True
            "swap_total": swap_total,
 
            "updatetime": timesince2(updatetime),
 
            "script_filename": self.request.META.get("SCRIPT_FILENAME", "???"),
    def lastupdate_time2(self, obj):
        return timesince2(obj.lastupdate_time)
    lastupdate_time2.short_description = _("last update")
    lastupdate_time2.admin_order_field = "lastupdate_time"
    lastupdate_time2.allow_tags = True
 
    def life_time(self, obj):
        return timesince2(obj.start_time, obj.lastupdate_time)