Comments (2)
Oh sure. I think my task description was lacking the context. When I said django printing out, I meant Django serialising the DateTime fields. So, we use django-rest framework.
Apparently, you can control it over a settings, like https://www.django-rest-framework.org/api-guide/fields/#datetimefield and this should help us, I guess.
The strings are for the clients on the response, for eg: the createdAt
in http://docs.quarantinehelp.space/#/Explore%20and%20assign%20requests%20as%20a%20HL%20participant/get_api_v1_crises__crisisId__affected_participants__participantId__requests_
from quarantine-help-api.
Django prints out weird stuff to the frontend, like
"2020-04-04T11:17:37.784674Z",
Lets push it to ISO format"2019-09-27T11:01:41.928158+00:00",
If you need humanized/localized output then you might want to use babel and pytz. I used to do something like the following
from datetime import datetime
from pytz import timezone
from babel.dates import format_time
import pytz
FORMAT = '%H:%M / %d-%m-%Y'
MONTHS = ('Jan.', 'Feb.', 'Mar.', 'April.', 'May.', 'June.',
'July.', 'Aug.', 'Sep.', 'Oct.', 'Nov.', 'Dec.')
# dummy function if you want to use i18 later and the real _ translation
def _(dummy):
return dummy
def format_datetime_human(to_format, locale='en', timezoneinfo='Asia/Calcutta'):
import datetime as DT
import pytz
utc = pytz.utc
to_format = DT.datetime(int(to_format.year), int(to_format.month), int(to_format.day), int(to_format.hour), int(to_format.minute))
utc_date = utc.localize(to_format)
tzone = pytz.timezone(timezoneinfo)
tzone_date = utc_date.astimezone(tzone)
month = MONTHS[int(tzone_date.month) - 1]
time_str = format_time(tzone_date, 'H:mm')
date_str = '{0} {1}'.format(tzone_date.day, _(month))
return "{0} {1}".format(date_str, time_str)
Then I can get output any way I like e.g.
>>> import timepy
>>> import datetime
>>> timepy.format_datetime_human(datetime.datetime.now())
'5 April. 0:04'
>>>
Or a template filter e.g. https://docs.djangoproject.com/en/dev/ref/contrib/humanize/#naturaltime
from quarantine-help-api.
Related Issues (20)
- Build a query to get people near your geo location
- Missing unit tests HOT 1
- Write a loaddata script to load some initial data for development HOT 3
- API to list and manage assigned requests as an HL participant HOT 3
- Related project : helpcovid HOT 2
- API to retrieve and update my details (say, address, etc). HOT 1
- Add documentation for APIs
- Anonymise user data on unprotected APIs
- Figure out how to start sending out emails HOT 3
- Proper exception handling at the backend
- Expire tokens at the backend
- Setup some sort of CI/CD for the repo?
- Abuse filter: setup mechanism to slow down users.
- Auto-convert openapi-schema.yml to openapi.json on commit to master
- Installation instruction for windows HOT 1
- Add FAQ section to README
- Integrate sentry with the mechanism
- API to assign a request from an affected participant HOT 1
- Notify AF participant when an HL participant has started working on their request
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quarantine-help-api.