RAD Studio Learn To Build A Python GUI For Manipulating Date, Time, And Timestamps Using Arrow Library In A Delphi Windows App

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,199
Credits
4,009
Learn To Build A Python GUI For Manipulating Date, Time, And Timestamps Using Arrow Library In A Delphi Windows App
By Muhammad Azizul Hakim April 15, 2021

Are you looking for powerful tools to manipulate or format dates, times, and timestamps, and build a nice GUI for them? You can build it easily by combining Для просмотра ссылки Войди или Зарегистрируйся and Для просмотра ссылки Войди или Зарегистрируйся library, inside Для просмотра ссылки Войди или Зарегистрируйся.

Arrow is a Python library that offers a sensible and human-friendly approach to creating, manipulating, formatting, and converting dates, times, and timestamps. It implements and updates the datetime type, plugging gaps in functionality and providing an intelligent module API that supports many common creation scenarios. Simply put, it helps you work with dates and times with fewer imports and a lot less code.

Arrow is named after the Для просмотра ссылки Войди или Зарегистрируйся and is heavily inspired by Для просмотра ссылки Войди или Зарегистрируйся and Для просмотра ссылки Войди или Зарегистрируйся.

1. Why use Arrow over built-in modules?​

Python’s standard library and some other low-level modules have a near-complete date, time, and timezone functionality, but don’t work very well from a usability perspective:
  • Too many modules: datetime, time, calendar, dateutil, pytz, and more.
  • Too many types: date, time, datetime, tzinfo, timedelta, relativedelta, etc.
  • Time Zones and timestamp conversions are verbose and unpleasant.
  • Timezone naivety is the norm.
  • Gaps in functionality: ISO 8601 parsing, timespans, and humanization issues.

2. Features​

  • Fully-implemented, drop-in replacement for datetime
  • Support for Python 3.6+
  • Timezone-aware and UTC by default
  • Super-simple creation options for many common input scenarios
  • shift method with support for relative offsets, including weeks
  • Format and parse strings automatically
  • Wide support for the Для просмотра ссылки Войди или Зарегистрируйся standard
  • Timezone conversion
  • Support for dateutil, pytz, and Zone Info tzinfo objects
  • Generates time spans, ranges, floors, and ceilings for time frames ranging from microsecond to year
  • Humanize dates and times with a growing list of contributed locales
  • Extensible for your own Arrow-derived types
  • Full support for PEP 484-style type hints

3. Hands-On​

This post will guide you on how to run various manipulations to dates, times, and timestamps using Python’s Arrow library and then display it in the Delphi Windows GUI app using Python for Delphi.

First, open and run our Python GUI using project Demo1 from Python4Delphi with RAD Studio. Then insert the script into the lower Memo, click the Execute button, and get the result in the upper Memo. You can find the Demo1 source on Для просмотра ссылки Войди или Зарегистрируйся. The behind the scene details of how Delphi manages to run your Python code in this amazing Python GUI can be found at this Для просмотра ссылки Войди или Зарегистрируйся.
1618815502494.png
And then, let’s run these code to print out some operations in our Python GUI:
Python:
import arrow
 
print(arrow.get('2017-05-11T21:23:58.970460+07:00'))
 
utc = arrow.utcnow()
print(utc)
 
utc = utc.shift(hours=-1)
print(utc)
 
local = utc.to('US/Pacific')
print(local)
 
print(local.timestamp())
 
print(local.format())
 
print(local.format('YYYY-MM-DD HH:mm:ss ZZ'))
 
# English
print(local.humanize())
# Korean
print(local.humanize(locale='ko_kr'))
# Japanese
print(local.humanize(locale='ja_jp'))
# Russian
print(local.humanize(locale='ru'))
# China
print(local.humanize(locale='zh_cn'))
1618815535539.png
Congratulations, now you have learned how to run various manipulations to dates, times, and timestamps using Python’s Arrow library and then display it in the Delphi Windows GUI app using Python for Delphi!

Check out the Arrow library for Python and use it in your projects: Для просмотра ссылки Войди или Зарегистрируйся and

Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi: Для просмотра ссылки Войди или Зарегистрируйся