GithubHelp home page GithubHelp logo

hustcc / timeago Goto Github PK

View Code? Open in Web Editor NEW
223.0 8.0 37.0 120 KB

:hourglass: Simple library used to format datetime with `*** time ago` statement. eg: "3 hours ago".

Home Page: http://timeago.org

License: MIT License

Python 99.65% Shell 0.09% JavaScript 0.26%
timeago datetime format-datetime python multi-language

timeago's People

Contributors

0xflotus avatar aashrut avatar ajphukan avatar avrong avatar hustcc avatar iteanjd123 avatar jenca-adam avatar justinwhite avatar lolobosse avatar meyt avatar naglis avatar nmb10 avatar seluj78 avatar zjuchenyuan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

timeago's Issues

Example code does not work!

○ python time.py
Traceback (most recent call last):
  File "time.py", line 6, in <module>
    print (timeago.format(date, now, locale='zh_CN')) # will print <removed because encoding>
NameError: name 'date' is not defined

.

○ python time.py
Traceback (most recent call last):
  File "time.py", line 9, in <module>
    print (timeago.format(date, now)) # will print 3 minutes ago
NameError: name 'date' is not defined

.

○ python time.py
Traceback (most recent call last):
  File "time.py", line 12, in <module>
    print (timeago.format(datetime.timedelta(seconds = 60 * 3.4))) # will print 3 minutes ago
  File "/usr/lib/python2.6/site-packages/timeago/__init__.py", line 25, in format
    diff_seconds = date.total_seconds()
AttributeError: 'datetime.timedelta' object has no attribute 'total_seconds'

.

○ python time.py
Traceback (most recent call last):
  File "time.py", line 15, in <module>
    print (timeago.format(datetime.date(2016, 5, 27), now))
  File "/usr/lib/python2.6/site-packages/timeago/__init__.py", line 33, in format
    raise ParameterUnvalid('the parameter `date` should be datetime / timedelta, or datetime formated string.')
timeago.excepts.ParameterUnvalid: 'the parameter `date` should be datetime / timedelta, or datetime formated string.'

.

○ python time.py
Traceback (most recent call last):
  File "time.py", line 18, in <module>
    print (timeago.format(datetime.date(2016, 5, 27), now))
  File "/usr/lib/python2.6/site-packages/timeago/__init__.py", line 33, in format
    raise ParameterUnvalid('the parameter `date` should be datetime / timedelta, or datetime formated string.')
timeago.excepts.ParameterUnvalid: 'the parameter `date` should be datetime / timedelta, or datetime formated string.'

.

○ python time.py
Traceback (most recent call last):
  File "time.py", line 21, in <module>
    print (timeago.format('2016-05-27 12:12:12', '2016-05-27 12:12:03')) # will print just now
  File "/usr/lib/python2.6/site-packages/timeago/__init__.py", line 37, in format
    diff_seconds = (now - date).total_seconds()
AttributeError: 'datetime.timedelta' object has no attribute 'total_seconds'

.

○ python --version
Python 2.6.6

typo in README?

README says:

print (timeago.format('2016-05-27 12:12:12', '2016-05-27 12:12:03')) # will print just now

but I got "a while" as the output

I installed timeago by pip install timeago, and timeago.__version__ is '1.0.7'

Please include the future

Please include the future so that the answer is “in X” if date > now, corresponding to “X ago” if date < now. And perhaps a “just now” if date == now.

Locales not imported with PyInstaller

Example:

import time
import timeago

timestamp = time.time() - 30
print(timeago.format(timestamp))

PyInstaller command:

$ pyinstaller -F -c --noupx -i NONE main.py

Output:

Traceback (most recent call last):
  File "timeago\locales\__init__.py", line 25, in timeago_template
ModuleNotFoundError: No module named 'timeago.locales.en'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 7, in <module>
    print(timeago.format(timestamp))
  File "timeago\__init__.py", line 80, in format
  File "timeago\locales\__init__.py", line 29, in timeago_template
[28604] Failed to execute script 'main' due to unhandled exception!

Python 3.10.1
PyInstaller 4.8
timeago 1.0.15

The PyInstaller documentation provides examples of how to add hooks for hidden imports. There is also an example package repo.

A temporary workaround is to add each locale module manually using --hidden-import 'timeago.locales.<locale>'

I haven't worked with PyInstaller hooks, but it looks easy to implement. I can try to make a PR if needed when I look at it further.

Remove "in X hours ago" ??

Hi, How do I remove "IN X HOURS AGO", I only want it to show "X hours/days/minutes ago" and not "in X hours ago"
It does work, but on some instances it shows "3 hours ago" and in some other instances it shows "in 3 hours"...
Using Python..

`

    now = datetime.datetime.now() + datetime.timedelta(seconds=60 * 3.4)

    date = datetime.datetime.now()

    time_ago = (timeago.format(streamer_channel_info['last_seen']))`

timeago 1.0.12 refuses to install on Windows 10

C:\WINDOWS\system32>pip install timeago --upgrade
Collecting timeago
  Using cached https://files.pythonhosted.org/packages/70/c7/3a1ccd78d542e592534f4c74e63ead33d5f11977b0e26d061e022ed285ed/timeago-1.0.12.tar.gz
    ERROR: Command errored out with exit status 1:
     command: 'c:\python37\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\AlexFlipnote\\AppData\\Local\\Temp\\pip-install-6k63qzau\\timeago\\setup.py'"'"'; __file__='"'"'C:\\Users\\AlexFlipnote\\AppData\\Local\\Temp\\pip-install-6k63qzau\\timeago\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\AlexFlipnote\AppData\Local\Temp\pip-install-6k63qzau\timeago\pip-egg-info'
         cwd: C:\Users\AlexFlipnote\AppData\Local\Temp\pip-install-6k63qzau\timeago\
    Complete output (9 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\AlexFlipnote\AppData\Local\Temp\pip-install-6k63qzau\timeago\setup.py", line 12, in <module>
        long_description = readme(),
      File "C:\Users\AlexFlipnote\AppData\Local\Temp\pip-install-6k63qzau\timeago\setup.py", line 7, in readme
        return f.read()
      File "c:\python37\lib\encodings\cp1252.py", line 23, in decode
        return codecs.charmap_decode(input,self.errors,decoding_table)[0]
    UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 805: character maps to <undefined>
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Current Python version: Python 3.7.4
Tried versions: 3.7.6, 3.8.1
OS: Windows 10 Pro

Note: It does work to install it on my Debian 8.10 server, as a side-note.

Tag the source

It would be very helpful if you could tag releases as well again. This would enable distributions who want to get the source from GitHub instead of PyPI.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.