Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
A tool for extracting datetime intervals from Hungarian sentences and turning datetime objects into Hungarian text.
A tool for extracting datetime intervals from Hungarian sentences and turning datetime objects into Hungarian text.
Install and try the package with pip install hun-date-parser
from hun_date_parser import text2datetime
from datetime import datetime
text2datetime('találkozzunk jövő kedd délután!', now=datetime(2020, 12, 27))
# [{'start_date' datetime.datetime(2020, 12, 29, 17, 59, 59)}]
text2datetime('találkozzunk jövő héten szombaton háromnegyed nyolc előtt két perccel', now=datetime(2020, 12, 27))
# [{'start_date' datetime.datetime(2021, 1, 2, 7, 43, 59)}]
text2datetime('találkozzunk jövő héten szombaton este háromnegyed nyolc előtt két perccel', now=datetime(2020, 12, 27))
# [{'start_date' datetime.datetime(2021, 1, 2, 19, 43, 59)}]
The date parser is also capable of parsing explicit intervals from the text even when only one side of the interval is specified.
from hun_date_parser import text2datetime
from datetime import datetime
text2datetime('2020 decemberétől 2021 januárig', now=datetime(2020, 12, 27))
# [{'start_date' datetime.datetime(2021, 1, 31, 23, 59, 59)}]
text2datetime('2021 januárig', now=datetime(2020, 12, 27))
# [{'start_date' datetime.datetime(2021, 1, 31, 23, 59, 59)}]
If not specified otherwise, relative dates (eg.: tomorrow, next week, etc.) are calculated relative to the current datetime, at the time when the function is called. The now
parameter can be used for parsing relative datetimes relative to any timestamp other than the current time.
Our parser implements a rule-based strategy to interpret a diverse array of date and time formats, utilizing grammatical inflection to parse intervals.
The following formats are currently supported:
2020-01-15
, 2020-12-30-án
, 2020.12.29
.tavaly február
, 2020 február 3
, jövő március
, jövő február 12-én
, március elsején
.tegnap
, ma
, holnap
, idén
, tavaly
, múlt héten
, a múlt hónapban
, idei események
.múlt vasárnap
, kedden
, ezen a heten hétfőn
, jövő héten szerdán
.1 héttel ezelőtt
, 6 nappal ezelőtt
, 5 nap múlva
.az előző két hétben
, az előző két évi adatok
, az előző 10 nap eredménye
.este fél 8
, reggel nyolc előtt hat perccel
, nyolc óra nyolc perckor
, 20 óra 49 perckor
, este negyed 8 előtt 6 perccel
.16h-kor
.február 13-tól 17-ig
, keddtől péntekig
, januártól februárig
, 2020-10-12-től 2020-11-01-ig
.keddtől
, február elsejéig
.For the function text2datetime
, the parameter search_scope
is used to specify the desired time interval for parsing inputs.
SearchScopes.NOT_RESTRICTED
, does not restrict whether the scope of the search is in the past or the future.
SearchScopes.FUTURE_DAY
.
SearchScopes.PAST_SEARCH
.
The flag realistic_year_required
can be set in order to minimize false matches, it generally restricts year mentions to be between 1900 and 2100.
100000 nap múlva
).An example:
from hun_date_parser import text2datetime
from datetime import datetime
from hun_date_parser.utils import SearchScopes
text2datetime('augusztus', now=datetime(2023, 6, 7), search_scope=SearchScopes.PAST_SEARCH)
# [{'start_date': datetime.datetime(2022, 8, 1, 0, 0),
# 'end_date': datetime.datetime(2022, 8, 31, 23, 59, 59)}]
text2datetime('péntek', now=datetime(2023, 6, 7), search_scope=SearchScopes.PAST_SEARCH)
# [{'start_date': datetime.datetime(2023, 6, 2, 0, 0),
# 'end_date': datetime.datetime(2023, 6, 2, 23, 59, 59)}]
text2datetime('péntek', now=datetime(2023, 6, 7), search_scope=SearchScopes.NOT_RESTRICTED)
# [{'start_date': datetime.datetime(2023, 6, 9, 0, 0),
# 'end_date': datetime.datetime(2023, 6, 9, 23, 59, 59)}]
The duration parser can extract the duration in minutes from various expressions found in sentences.
The parser is capable of understanding a variety of duration expressions. Here are the primary formats it recognizes:
1 óra 45 perc
, egy óra 30 perc
, 2 óra 15 perc
1 óra
, egy óra
, 2 órát
, 3,5 óra
háromnegyed óra
, egy és negyed óra
, kettő és fél óra
from hun_date_parser import parse_duration
print(parse_duration('45 perc')) # Output: 45
print(parse_duration('1 és negyed óra')) # Output: 75
The library is also capable of turning datetime objects into their Hungarian text representation.
from hun_date_parser import datetime2text
from datetime import datetime
datetime2text(datetime(2020, 12, 20, 18, 34), now=datetime(2020, 12, 27), time_precision=2)
# {'dates': ['múlt héten vasárnap', '2020 december 20'],
# 'times'34', 'este hat óra harmincnégy perc', 'este fél 7 után 4 perccel']}
This project is licensed under MIT license. Feel free to use it in your own projects.
Any help or feedback in further developing the library is welcome!
FAQs
A tool for extracting datetime intervals from Hungarian sentences and turning datetime objects into Hungarian text.
We found that hun-date-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.