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.
Python module to convert various time strings into datetime objects, written in Rust.
import fuzzydate as fd
# If current time is April 1st 2023 12PM UTC...
fd.to_datetime('1 hour ago') # 2023-04-01 11:00:00+00:00
fd.to_datetime('last week') # 2023-03-20 12:00:00+00:00
fd.to_datetime('-1 week') # 2023-03-25 12:00:00+00:00
fd.to_datetime('last week midnight') # 2023-03-20 00:00:00+00:00
fd.to_datetime('-1d 2h 5min 10s') # 2023-03-31 09:54:50+00:00
fd.to_datetime('tomorrow') # 2023-04-02 00:00:00+00:00
fd.to_datetime('prev Monday') # 2023-03-27 00:00:00+00:00
fd.to_datetime('last day of this month') # 2023-04-30 00:00:00+00:00
# Anything invalid raises a ValueError
fd.to_datetime('next Summer')
# ValueError: Unable to convert "next Summer" into datetime
import fuzzydate as fd
fd.to_seconds('1h 4min') # 3840.0
fd.to_seconds('+2 days') # 172800.0
fd.to_seconds('-1 hour') # -3600.0
fd.to_seconds('1 week') # 604800.0
# Anything other than an exact length of time raises a ValueError
fd.to_seconds('last week')
# ValueError: Unable to convert "last week" into seconds
# Because years and months have varying amount of seconds, using
# them raises a ValueError
fd.to_seconds('1m 2w 30min')
# ValueError: Converting months into seconds is not supported
import fuzzydate as fd
fd.to_duration(3840.0) # 1hr 4min
fd.to_duration(3840.0, units='long') # 1 hour 4 minutes
fd.to_duration(3840.0, units='short') # 1h 4min
fd.to_duration(3840.0, max'min', min='min') # 64min
import fuzzydate as fd
fd.config.add_tokens({
'måndag': fd.token.WDAY_MON,
'dagar': fd.token.LONG_UNIT_DAY,
})
fd.config.add_patterns({
'nästa [wday]': fd.pattern.NEXT_WDAY,
})
assert fd.to_date('next Monday') == fd.to_date('nästa Måndag')
assert fd.to_date('+5 days') == fd.to_date('+5 dagar')
assert fd.to_seconds('+5 days') == fd.to_seconds('+5 dagar')
fd.config.units = {
fd.unit.DAY: 'dag',
fd.unit.DAYS: 'dagar',
}
assert fd.to_duration(86400.0) == '1 dag'
pip install fuzzy-date
now
, today
, tomorrow
, yesterday
midnight
last
, prev
, this
, next
or +
, -
next week
, next month
, next year
next Mon
, next Monday
(s)ec
, min
, (h)r
, (d)ay
, (w)eek
, (m)onth
, (y)ear
last/first day of
@1680307200
2023-04-01
, 04/01/2023
, 01.04.2023
April 1st 2023
, April 1 2023
, 1 April 2023
April 1st
, April 1
, 1 April
2023-04-01 12:00
, 2023-04-01 12:00:00
2pm
, 2:00 pm
fuzzydate.to_date(
source: str,
today: datetime.date = None,
weekday_start_mon: bool = True) -> datetime.date
fuzzydate.to_datetime(
source: str,
now: datetime.datetime = None,
weekday_start_mon: bool = True) -> datetime.datetime
fuzzydate.to_duration(
seconds: float,
units: str = None,
max: str = 'w',
min: str = 's') -> str
fuzzydate.to_seconds(
source: str) -> float
# Read-only
fuzzydate.config.patterns: dict[str, str]
fuzzydate.config.tokens: dict[str, int]
# Read-write
fuzzydate.config.units: dict[str, str]
fuzzydate.config.units_long: dict[str, str]
fuzzydate.config.units_short: dict[str, str]
fuzzydate.config.add_patterns(
tokens: dict[str, str]) -> None
fuzzydate.config.add_tokens(
tokens: dict[str, int]) -> None
This library was born out of the need to accept various user inputs for date range start and end times, to convert user time tracking entries into exact durations etc. All very much alike to what timelib does.
Other implementations are available, but I did find one that would have worked for me - usually they were missing support for some key wording I needed, or handled user vagueness and timezones in a different way.
Also, I kinda wanted to learn Rust via some example project as well.
MIT
FAQs
Convert various time strings into datetime objects
We found that fuzzy-date 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.