hustcc / timeago Goto Github PK
View Code? Open in Web Editor NEW:hourglass: Simple library used to format datetime with `*** time ago` statement. eg: "3 hours ago".
Home Page: http://timeago.org
License: MIT License
:hourglass: Simple library used to format datetime with `*** time ago` statement. eg: "3 hours ago".
Home Page: http://timeago.org
License: MIT License
○ 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
@ratiofu is right (I also speak german).
Merge hustcc/timeago.js#231 into this repo as well
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 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.
👋 FYI, it looks like sdist is missing on pypi for 1.0.16 release.
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.
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']))`
Not to have to use editable
packages?
Thx
Import these locales properly in Python:
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.
I found the islandic translation on hustcc/timeago.js#232.
@gylfiolafsson can we use it in python as well?
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.