예제 #1
0
def age(curdate):
    """
    turns a datetime into an age string.
    
    :param curdate: datetime object
    :rtype: unicode
    :returns: unicode words describing age
    """

    from datetime import datetime
    from webhelpers.date import time_ago_in_words

    _ = lambda s:s

    if not curdate:
        return ''

    agescales = [(_(u"year"), 3600 * 24 * 365),
                 (_(u"month"), 3600 * 24 * 30),
                 (_(u"day"), 3600 * 24),
                 (_(u"hour"), 3600),
                 (_(u"minute"), 60),
                 (_(u"second"), 1), ]

    age = datetime.now() - curdate
    age_seconds = (age.days * agescales[2][1]) + age.seconds
    pos = 1
    for scale in agescales:
        if scale[1] <= age_seconds:
            if pos == 6:pos = 5
            return '%s %s' % (time_ago_in_words(curdate,
                                                agescales[pos][0]), _('ago'))
        pos += 1

    return _(u'just now')
예제 #2
0
 def timestamp(self):
     today = datetime.date.today()
     yesterday = today - datetime.timedelta(days=1)
     if self.time.date() == today:
         return time_ago_in_words(self.time, granularity="minute") + " ago"
     elif self.time.date() == yesterday:
         return self.time.strftime("yesterday at  %I:%M%p").lower()
     else:
         return self.time.strftime("%a %b %d, %Y")
예제 #3
0
 def created_in_words(self):
     #TODO
     # value /= 1000
     # if value > 365 * 24 * 60 * 60:
     #     granularity = 'month'
     # else:
     #     granularity = 'day'
     granularity = 'day'
     return time_ago_in_words(self.created, granularity=granularity, round=True)
예제 #4
0
def time_ago(from_time):
    if not from_time:
        return None
    if isinstance(from_time, basestring):
        from_time = api_datestr_to_datetime(from_time)
    time_ago = time_ago_in_words(from_time, granularity='minute', round=True)
    match = re.match("^(less than ){0,1}\d+ [a-z]+", time_ago)
    if match:
        part = match.group(0)
        part = part.replace("minute", "min")
        part = part.replace("second", "sec")
        return part
    else:
        user_log.error("Failed to shorten time_ago:"+time_ago)
        return time_ago
예제 #5
0
def profile(request):
    session = request.session
    user = UserData.get_user(session['email'])
    if user[0]:
        print user[1].user_reg_date
        user_dict = {
            'email': user[1].user_email,
            'name': user[1].user_name,
            'reg_date': user[1].user_reg_date.ctime(),
            'last_log_in': time_ago_in_words(user[1].user_last_logged_on, granularity='minute'),
            'country': user[1].user_country
        }

        profile_name = user[1].user_name
        return {'user_dict': user_dict, 'profile_name': profile_name}
    else:
        return {}
예제 #6
0
def age(curdate):
    """
    turns a datetime into an age string.

    :param curdate: datetime object
    :rtype: unicode
    :returns: unicode words describing age
    """

    from datetime import datetime
    from webhelpers.date import time_ago_in_words

    _ = lambda s: s

    if not curdate:
        return ''

    agescales = [
        (_(u"year"), 3600 * 24 * 365),
        (_(u"month"), 3600 * 24 * 30),
        (_(u"day"), 3600 * 24),
        (_(u"hour"), 3600),
        (_(u"minute"), 60),
        (_(u"second"), 1),
    ]

    age = datetime.now() - curdate
    age_seconds = (age.days * agescales[2][1]) + age.seconds
    pos = 1
    for scale in agescales:
        if scale[1] <= age_seconds:
            if pos == 6:
                pos = 5
            return '%s %s' % (time_ago_in_words(curdate,
                                                agescales[pos][0]), _('ago'))
        pos += 1

    return _(u'just now')
예제 #7
0
 def created_in_words(self):
     return time_ago_in_words(self.created)
예제 #8
0
파일: models.py 프로젝트: wormone/FlaskBlog
 def created_in_words(self):
     return time_ago_in_words(self.created)
예제 #9
0
def time_ago_in_words_from_str(date_str, granularity='month'):
    if date_str:
        return date.time_ago_in_words(date_str_to_datetime(date_str),
                                      granularity=granularity)
    else:
        return _('Unknown')
예제 #10
0
파일: helpers.py 프로젝트: HHS/ckan
def time_ago_in_words_from_str(date_str, granularity='month'):
    if date_str:
        return date.time_ago_in_words(date_str_to_datetime(date_str),
                                      granularity=granularity)
    else:
        return _('Unknown')
예제 #11
0
 def last_seen_time_ago(self):
     return time_ago_in_words(self.last_seen)
예제 #12
0
파일: Post.py 프로젝트: cuoretech/dowork
 def getTimeWords(self):
     return time_ago_in_words(self.getTime())
예제 #13
0
 def created_in_words(self):
     return time_ago_in_words(self.created, granularity="minute")
예제 #14
0
파일: helpers.py 프로젝트: kindly/ckantest
def time_ago_in_words_from_str(date_str, granularity='month'):
    return date.time_ago_in_words(date_str_to_datetime(date_str), granularity=granularity)