diff --git a/articles.html b/articles.html
index abc896c..4b34237 100644
--- a/articles.html
+++ b/articles.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles10.html b/articles10.html
index abc896c..4b34237 100644
--- a/articles10.html
+++ b/articles10.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles11.html b/articles11.html
index abc896c..4b34237 100644
--- a/articles11.html
+++ b/articles11.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles12.html b/articles12.html
index abc896c..4b34237 100644
--- a/articles12.html
+++ b/articles12.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles13.html b/articles13.html
index abc896c..4b34237 100644
--- a/articles13.html
+++ b/articles13.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles14.html b/articles14.html
index abc896c..4b34237 100644
--- a/articles14.html
+++ b/articles14.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles15.html b/articles15.html
index abc896c..4b34237 100644
--- a/articles15.html
+++ b/articles15.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles16.html b/articles16.html
index abc896c..4b34237 100644
--- a/articles16.html
+++ b/articles16.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles17.html b/articles17.html
index abc896c..4b34237 100644
--- a/articles17.html
+++ b/articles17.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles18.html b/articles18.html
index abc896c..4b34237 100644
--- a/articles18.html
+++ b/articles18.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles19.html b/articles19.html
index abc896c..4b34237 100644
--- a/articles19.html
+++ b/articles19.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles2.html b/articles2.html
index abc896c..4b34237 100644
--- a/articles2.html
+++ b/articles2.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles20.html b/articles20.html
index abc896c..4b34237 100644
--- a/articles20.html
+++ b/articles20.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles21.html b/articles21.html
index abc896c..4b34237 100644
--- a/articles21.html
+++ b/articles21.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles22.html b/articles22.html
index abc896c..4b34237 100644
--- a/articles22.html
+++ b/articles22.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles23.html b/articles23.html
index abc896c..4b34237 100644
--- a/articles23.html
+++ b/articles23.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles24.html b/articles24.html
index abc896c..4b34237 100644
--- a/articles24.html
+++ b/articles24.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles25.html b/articles25.html
index abc896c..4b34237 100644
--- a/articles25.html
+++ b/articles25.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles26.html b/articles26.html
index abc896c..4b34237 100644
--- a/articles26.html
+++ b/articles26.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles27.html b/articles27.html
index abc896c..4b34237 100644
--- a/articles27.html
+++ b/articles27.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles28.html b/articles28.html
index abc896c..4b34237 100644
--- a/articles28.html
+++ b/articles28.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles29.html b/articles29.html
index abc896c..4b34237 100644
--- a/articles29.html
+++ b/articles29.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles3.html b/articles3.html
index abc896c..4b34237 100644
--- a/articles3.html
+++ b/articles3.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles30.html b/articles30.html
index abc896c..4b34237 100644
--- a/articles30.html
+++ b/articles30.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles31.html b/articles31.html
index abc896c..4b34237 100644
--- a/articles31.html
+++ b/articles31.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles32.html b/articles32.html
index abc896c..4b34237 100644
--- a/articles32.html
+++ b/articles32.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles33.html b/articles33.html
index abc896c..4b34237 100644
--- a/articles33.html
+++ b/articles33.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles34.html b/articles34.html
index abc896c..4b34237 100644
--- a/articles34.html
+++ b/articles34.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles35.html b/articles35.html
index abc896c..4b34237 100644
--- a/articles35.html
+++ b/articles35.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles36.html b/articles36.html
index abc896c..4b34237 100644
--- a/articles36.html
+++ b/articles36.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles37.html b/articles37.html
index abc896c..4b34237 100644
--- a/articles37.html
+++ b/articles37.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles38.html b/articles38.html
index abc896c..4b34237 100644
--- a/articles38.html
+++ b/articles38.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles39.html b/articles39.html
index abc896c..4b34237 100644
--- a/articles39.html
+++ b/articles39.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles4.html b/articles4.html
index abc896c..4b34237 100644
--- a/articles4.html
+++ b/articles4.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles40.html b/articles40.html
index abc896c..4b34237 100644
--- a/articles40.html
+++ b/articles40.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles41.html b/articles41.html
index abc896c..4b34237 100644
--- a/articles41.html
+++ b/articles41.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles42.html b/articles42.html
index abc896c..4b34237 100644
--- a/articles42.html
+++ b/articles42.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles43.html b/articles43.html
index abc896c..4b34237 100644
--- a/articles43.html
+++ b/articles43.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles44.html b/articles44.html
index abc896c..4b34237 100644
--- a/articles44.html
+++ b/articles44.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles45.html b/articles45.html
index abc896c..4b34237 100644
--- a/articles45.html
+++ b/articles45.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles46.html b/articles46.html
index abc896c..4b34237 100644
--- a/articles46.html
+++ b/articles46.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles47.html b/articles47.html
index abc896c..4b34237 100644
--- a/articles47.html
+++ b/articles47.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles48.html b/articles48.html
index abc896c..4b34237 100644
--- a/articles48.html
+++ b/articles48.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles49.html b/articles49.html
index abc896c..4b34237 100644
--- a/articles49.html
+++ b/articles49.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles5.html b/articles5.html
index abc896c..4b34237 100644
--- a/articles5.html
+++ b/articles5.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles50.html b/articles50.html
index abc896c..4b34237 100644
--- a/articles50.html
+++ b/articles50.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles51.html b/articles51.html
index abc896c..4b34237 100644
--- a/articles51.html
+++ b/articles51.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles52.html b/articles52.html
index abc896c..4b34237 100644
--- a/articles52.html
+++ b/articles52.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles53.html b/articles53.html
index abc896c..4b34237 100644
--- a/articles53.html
+++ b/articles53.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles54.html b/articles54.html
index abc896c..4b34237 100644
--- a/articles54.html
+++ b/articles54.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles55.html b/articles55.html
index abc896c..4b34237 100644
--- a/articles55.html
+++ b/articles55.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles6.html b/articles6.html
index abc896c..4b34237 100644
--- a/articles6.html
+++ b/articles6.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles7.html b/articles7.html
index abc896c..4b34237 100644
--- a/articles7.html
+++ b/articles7.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles8.html b/articles8.html
index abc896c..4b34237 100644
--- a/articles8.html
+++ b/articles8.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/articles9.html b/articles9.html
index abc896c..4b34237 100644
--- a/articles9.html
+++ b/articles9.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html b/author/.html
index a86ad32..beb0acf 100644
--- a/author/.html
+++ b/author/.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html10 b/author/.html10
index a86ad32..beb0acf 100644
--- a/author/.html10
+++ b/author/.html10
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html11 b/author/.html11
index a86ad32..beb0acf 100644
--- a/author/.html11
+++ b/author/.html11
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html12 b/author/.html12
index a86ad32..beb0acf 100644
--- a/author/.html12
+++ b/author/.html12
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html13 b/author/.html13
index a86ad32..beb0acf 100644
--- a/author/.html13
+++ b/author/.html13
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html14 b/author/.html14
index a86ad32..beb0acf 100644
--- a/author/.html14
+++ b/author/.html14
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html15 b/author/.html15
index a86ad32..beb0acf 100644
--- a/author/.html15
+++ b/author/.html15
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html16 b/author/.html16
index a86ad32..beb0acf 100644
--- a/author/.html16
+++ b/author/.html16
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html17 b/author/.html17
index a86ad32..beb0acf 100644
--- a/author/.html17
+++ b/author/.html17
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html18 b/author/.html18
index a86ad32..beb0acf 100644
--- a/author/.html18
+++ b/author/.html18
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html19 b/author/.html19
index a86ad32..beb0acf 100644
--- a/author/.html19
+++ b/author/.html19
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html2 b/author/.html2
index a86ad32..beb0acf 100644
--- a/author/.html2
+++ b/author/.html2
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html20 b/author/.html20
index a86ad32..beb0acf 100644
--- a/author/.html20
+++ b/author/.html20
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html21 b/author/.html21
index a86ad32..beb0acf 100644
--- a/author/.html21
+++ b/author/.html21
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html22 b/author/.html22
index a86ad32..beb0acf 100644
--- a/author/.html22
+++ b/author/.html22
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html23 b/author/.html23
index a86ad32..beb0acf 100644
--- a/author/.html23
+++ b/author/.html23
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html24 b/author/.html24
index a86ad32..beb0acf 100644
--- a/author/.html24
+++ b/author/.html24
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html25 b/author/.html25
index a86ad32..beb0acf 100644
--- a/author/.html25
+++ b/author/.html25
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html26 b/author/.html26
index a86ad32..beb0acf 100644
--- a/author/.html26
+++ b/author/.html26
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html27 b/author/.html27
index a86ad32..beb0acf 100644
--- a/author/.html27
+++ b/author/.html27
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html28 b/author/.html28
index a86ad32..beb0acf 100644
--- a/author/.html28
+++ b/author/.html28
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html29 b/author/.html29
index a86ad32..beb0acf 100644
--- a/author/.html29
+++ b/author/.html29
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html3 b/author/.html3
index a86ad32..beb0acf 100644
--- a/author/.html3
+++ b/author/.html3
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html30 b/author/.html30
index a86ad32..beb0acf 100644
--- a/author/.html30
+++ b/author/.html30
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html31 b/author/.html31
index a86ad32..beb0acf 100644
--- a/author/.html31
+++ b/author/.html31
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html32 b/author/.html32
index a86ad32..beb0acf 100644
--- a/author/.html32
+++ b/author/.html32
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html33 b/author/.html33
index a86ad32..beb0acf 100644
--- a/author/.html33
+++ b/author/.html33
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html34 b/author/.html34
index a86ad32..beb0acf 100644
--- a/author/.html34
+++ b/author/.html34
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html35 b/author/.html35
index a86ad32..beb0acf 100644
--- a/author/.html35
+++ b/author/.html35
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html36 b/author/.html36
index a86ad32..beb0acf 100644
--- a/author/.html36
+++ b/author/.html36
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html37 b/author/.html37
index a86ad32..beb0acf 100644
--- a/author/.html37
+++ b/author/.html37
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html38 b/author/.html38
index a86ad32..beb0acf 100644
--- a/author/.html38
+++ b/author/.html38
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html39 b/author/.html39
index a86ad32..beb0acf 100644
--- a/author/.html39
+++ b/author/.html39
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html4 b/author/.html4
index a86ad32..beb0acf 100644
--- a/author/.html4
+++ b/author/.html4
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html40 b/author/.html40
index a86ad32..beb0acf 100644
--- a/author/.html40
+++ b/author/.html40
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html41 b/author/.html41
index a86ad32..beb0acf 100644
--- a/author/.html41
+++ b/author/.html41
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html42 b/author/.html42
index a86ad32..beb0acf 100644
--- a/author/.html42
+++ b/author/.html42
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html43 b/author/.html43
index a86ad32..beb0acf 100644
--- a/author/.html43
+++ b/author/.html43
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html44 b/author/.html44
index a86ad32..beb0acf 100644
--- a/author/.html44
+++ b/author/.html44
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html45 b/author/.html45
index a86ad32..beb0acf 100644
--- a/author/.html45
+++ b/author/.html45
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html46 b/author/.html46
index a86ad32..beb0acf 100644
--- a/author/.html46
+++ b/author/.html46
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html47 b/author/.html47
index a86ad32..beb0acf 100644
--- a/author/.html47
+++ b/author/.html47
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html48 b/author/.html48
index a86ad32..beb0acf 100644
--- a/author/.html48
+++ b/author/.html48
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html49 b/author/.html49
index a86ad32..beb0acf 100644
--- a/author/.html49
+++ b/author/.html49
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html5 b/author/.html5
index a86ad32..beb0acf 100644
--- a/author/.html5
+++ b/author/.html5
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html50 b/author/.html50
index a86ad32..beb0acf 100644
--- a/author/.html50
+++ b/author/.html50
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html6 b/author/.html6
index a86ad32..beb0acf 100644
--- a/author/.html6
+++ b/author/.html6
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html7 b/author/.html7
index a86ad32..beb0acf 100644
--- a/author/.html7
+++ b/author/.html7
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html8 b/author/.html8
index a86ad32..beb0acf 100644
--- a/author/.html8
+++ b/author/.html8
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/author/.html9 b/author/.html9
index a86ad32..beb0acf 100644
--- a/author/.html9
+++ b/author/.html9
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
27 septembre 2023
diff --git a/code/index.html b/code/index.html
index 0ba03b3..556dd91 100644
--- a/code/index.html
+++ b/code/index.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index10.html b/code/index10.html
index 0ba03b3..556dd91 100644
--- a/code/index10.html
+++ b/code/index10.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index11.html b/code/index11.html
index 0ba03b3..556dd91 100644
--- a/code/index11.html
+++ b/code/index11.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index12.html b/code/index12.html
index 0ba03b3..556dd91 100644
--- a/code/index12.html
+++ b/code/index12.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index13.html b/code/index13.html
index 0ba03b3..556dd91 100644
--- a/code/index13.html
+++ b/code/index13.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index14.html b/code/index14.html
index 0ba03b3..556dd91 100644
--- a/code/index14.html
+++ b/code/index14.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index15.html b/code/index15.html
index 0ba03b3..556dd91 100644
--- a/code/index15.html
+++ b/code/index15.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index16.html b/code/index16.html
index 0ba03b3..556dd91 100644
--- a/code/index16.html
+++ b/code/index16.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index17.html b/code/index17.html
index 0ba03b3..556dd91 100644
--- a/code/index17.html
+++ b/code/index17.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index18.html b/code/index18.html
index 0ba03b3..556dd91 100644
--- a/code/index18.html
+++ b/code/index18.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index19.html b/code/index19.html
index 0ba03b3..556dd91 100644
--- a/code/index19.html
+++ b/code/index19.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index2.html b/code/index2.html
index 0ba03b3..556dd91 100644
--- a/code/index2.html
+++ b/code/index2.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index20.html b/code/index20.html
index 0ba03b3..556dd91 100644
--- a/code/index20.html
+++ b/code/index20.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index21.html b/code/index21.html
index 0ba03b3..556dd91 100644
--- a/code/index21.html
+++ b/code/index21.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index22.html b/code/index22.html
index 0ba03b3..556dd91 100644
--- a/code/index22.html
+++ b/code/index22.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index3.html b/code/index3.html
index 0ba03b3..556dd91 100644
--- a/code/index3.html
+++ b/code/index3.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index4.html b/code/index4.html
index 0ba03b3..556dd91 100644
--- a/code/index4.html
+++ b/code/index4.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index5.html b/code/index5.html
index 0ba03b3..556dd91 100644
--- a/code/index5.html
+++ b/code/index5.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index6.html b/code/index6.html
index 0ba03b3..556dd91 100644
--- a/code/index6.html
+++ b/code/index6.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index7.html b/code/index7.html
index 0ba03b3..556dd91 100644
--- a/code/index7.html
+++ b/code/index7.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index8.html b/code/index8.html
index 0ba03b3..556dd91 100644
--- a/code/index8.html
+++ b/code/index8.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/code/index9.html b/code/index9.html
index 0ba03b3..556dd91 100644
--- a/code/index9.html
+++ b/code/index9.html
@@ -36,16 +36,16 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
python , conversion
diff --git a/convert-string-to-duration.html b/convert-string-to-duration.html
index df5f39d..15a35a6 100644
--- a/convert-string-to-duration.html
+++ b/convert-string-to-duration.html
@@ -34,40 +34,51 @@
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value : str , target : Literal [ "days" , "hours" ]):
- """Convert a string to a number of hours, or days"""
+def string_to_duration ( value : str , target : Literal [ "days" , "hours" , "minutes" ]):
+ """Convert a string to a number of hours, days or minutes"""
num = int ( "" . join ( filter ( str . isdigit , value )))
- if target == "hours" :
- reconvert = True
+ # It's not possible to convert from a smaller unit to a greater one:
+ # - hours and minutes cannot be converted to days
+ # - minutes cannot be converted to hours
+ if ( target == "days" and ( "h" in value or "m" in value . replace ( "mo" , "" ))) or (
+ target == "hours" and "m" in value . replace ( "mo" , "" )
+ ):
+ msg = (
+ "Durations cannot be converted from a smaller to a greater unit. "
+ f "(trying to convert ' { value } ' to { target } )"
+ )
+ raise ValueError ( msg , value )
+ # Consider we're converting to minutes, do the eventual multiplication at the end.
if "h" in value :
- if target == "days" :
- raise ValueError ( "Invalid duration value" , value )
- num = num
- reconvert = False
+ num = num * 60
elif "d" in value :
- num = num
+ num = num * 60 * 24
elif "w" in value :
- num = num * 7
- elif "m" in value :
- num = num * 30
+ num = num * 60 * 24 * 7
+ elif "mo" in value :
+ num = num * 60 * 24 * 30 # considers 30d in a month
elif "y" in value :
- num = num * 365
+ num = num * 60 * 24 * 365
+ elif "m" in value :
+ num = num
else :
raise ValueError ( "Invalid duration value" , value )
- if target == "hours" and reconvert :
- num = num * 24
+ if target == "hours" :
+ num = num / 60
+ elif target == "days" :
+ num = num / 60 / 24
return num
diff --git a/feeds/.atom.xml b/feeds/.atom.xml
index 95cf4f1..014a1ba 100644
--- a/feeds/.atom.xml
+++ b/feeds/.atom.xml
@@ -1,51 +1,62 @@
Alexis Métaireau https://blog.notmyidea.org/ 2023-10-11T00:00:00+02:00 Convert string to duration 2023-10-11T00:00:00+02:00 2023-10-11T00:00:00+02:00 tag:blog.notmyidea.org,2023-10-11:/convert-string-to-duration.html <p>I found myself wanting to convert a string to a duration (int), for some configuration.</p>
<p>Something you can call like this:</p>
-<div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"days"</span><span class="p">)</span> <span class="c1"># returns 1</span>
-<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span> <span class="c1"># returns 24</span>
-<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span> <span class="c1"># returns 3 * 24 * 30</span>
+<div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"days"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"minutes"</span><span class="p">)</span>
</code></pre></div>
<p>The code :</p>
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span>
-
-<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value …</span></code></pre></div> <p>I found myself wanting to convert a string to a duration (int), for some configuration.</p>
+<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span> <span class="n">Literal</span><span class="p">[</span><span class="s2">"days …</span></code></pre></div><p>I found myself wanting to convert a string to a duration (int), for some configuration.</p>
<p>Something you can call like this:</p>
-<div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"days"</span><span class="p">)</span> <span class="c1"># returns 1</span>
-<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span> <span class="c1"># returns 24</span>
-<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span> <span class="c1"># returns 3 * 24 * 30</span>
+<div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"days"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"minutes"</span><span class="p">)</span>
</code></pre></div>
<p>The code :</p>
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span>
-
-<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span> <span class="n">Literal</span><span class="p">[</span><span class="s2">"days"</span><span class="p">,</span> <span class="s2">"hours"</span><span class="p">]):</span>
-<span class="w"> </span><span class="sd">"""Convert a string to a number of hours, or days"""</span>
+<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span> <span class="n">Literal</span><span class="p">[</span><span class="s2">"days"</span><span class="p">,</span> <span class="s2">"hours"</span><span class="p">,</span> <span class="s2">"minutes"</span><span class="p">]):</span>
+<span class="w"> </span><span class="sd">"""Convert a string to a number of hours, days or minutes"""</span>
<span class="n">num</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="s2">""</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">filter</span><span class="p">(</span><span class="nb">str</span><span class="o">.</span><span class="n">isdigit</span><span class="p">,</span> <span class="n">value</span><span class="p">)))</span>
- <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"hours"</span><span class="p">:</span>
- <span class="n">reconvert</span> <span class="o">=</span> <span class="kc">True</span>
+ <span class="c1"># It's not possible to convert from a smaller unit to a greater one:</span>
+ <span class="c1"># - hours and minutes cannot be converted to days</span>
+ <span class="c1"># - minutes cannot be converted to hours</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">target</span> <span class="o">==</span> <span class="s2">"days"</span> <span class="ow">and</span> <span class="p">(</span><span class="s2">"h"</span> <span class="ow">in</span> <span class="n">value</span> <span class="ow">or</span> <span class="s2">"m"</span> <span class="ow">in</span> <span class="n">value</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">"mo"</span><span class="p">,</span> <span class="s2">""</span><span class="p">)))</span> <span class="ow">or</span> <span class="p">(</span>
+ <span class="n">target</span> <span class="o">==</span> <span class="s2">"hours"</span> <span class="ow">and</span> <span class="s2">"m"</span> <span class="ow">in</span> <span class="n">value</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">"mo"</span><span class="p">,</span> <span class="s2">""</span><span class="p">)</span>
+ <span class="p">):</span>
+ <span class="n">msg</span> <span class="o">=</span> <span class="p">(</span>
+ <span class="s2">"Durations cannot be converted from a smaller to a greater unit. "</span>
+ <span class="sa">f</span><span class="s2">"(trying to convert '</span><span class="si">{</span><span class="n">value</span><span class="si">}</span><span class="s2">' to </span><span class="si">{</span><span class="n">target</span><span class="si">}</span><span class="s2">)"</span>
+ <span class="p">)</span>
+ <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
+ <span class="c1"># Consider we're converting to minutes, do the eventual multiplication at the end.</span>
<span class="k">if</span> <span class="s2">"h"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"days"</span><span class="p">:</span>
- <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"Invalid duration value"</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span>
- <span class="n">reconvert</span> <span class="o">=</span> <span class="kc">False</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span>
<span class="k">elif</span> <span class="s2">"d"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span>
<span class="k">elif</span> <span class="s2">"w"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">7</span>
- <span class="k">elif</span> <span class="s2">"m"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">30</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span> <span class="o">*</span> <span class="mi">7</span>
+ <span class="k">elif</span> <span class="s2">"mo"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span> <span class="o">*</span> <span class="mi">30</span> <span class="c1"># considers 30d in a month</span>
<span class="k">elif</span> <span class="s2">"y"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">365</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span> <span class="o">*</span> <span class="mi">365</span>
+ <span class="k">elif</span> <span class="s2">"m"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"Invalid duration value"</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
- <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"hours"</span> <span class="ow">and</span> <span class="n">reconvert</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">24</span>
+ <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"hours"</span><span class="p">:</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">/</span> <span class="mi">60</span>
+ <span class="k">elif</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"days"</span><span class="p">:</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">/</span> <span class="mi">60</span> <span class="o">/</span> <span class="mi">24</span>
<span class="k">return</span> <span class="n">num</span>
</code></pre></div> 2023, Semaine 40 2023-10-08T00:00:00+02:00 2023-10-08T00:00:00+02:00 tag:blog.notmyidea.org,2023-10-08:/2023-semaine-40.html
diff --git a/feeds/.rss.xml b/feeds/.rss.xml
index 7bafedc..86f07de 100644
--- a/feeds/.rss.xml
+++ b/feeds/.rss.xml
@@ -1,16 +1,16 @@
Alexis Métaireau https://blog.notmyidea.org/Wed, 11 Oct 2023 00:00:00 +0200 Convert string to duration https://blog.notmyidea.org/convert-string-to-duration.html<p>I found myself wanting to convert a string to a duration (int), for some configuration.</p>
<p>Something you can call like this:</p>
-<div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"days"</span><span class="p">)</span> <span class="c1"># returns 1</span>
-<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span> <span class="c1"># returns 24</span>
-<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span> <span class="c1"># returns 3 * 24 * 30</span>
+<div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"days"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"minutes"</span><span class="p">)</span>
</code></pre></div>
<p>The code :</p>
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span>
-
-<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value …</span></code></pre></div> Wed, 11 Oct 2023 00:00:00 +0200 tag:blog.notmyidea.org,2023-10-11:/convert-string-to-duration.html code python conversion 2023, Semaine 40 https://blog.notmyidea.org/2023-semaine-40.html
+<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span> <span class="n">Literal</span><span class="p">[</span><span class="s2">"days …</span></code></pre></div> Wed, 11 Oct 2023 00:00:00 +0200 tag:blog.notmyidea.org,2023-10-11:/convert-string-to-duration.html code python conversion 2023, Semaine 40 https://blog.notmyidea.org/2023-semaine-40.html
<p>Je me suis réservé les matins pour travailler, et je suis content du rythme que ça à donné à ma semaine. C’était aussi le retour des pomodoros !</p>
<h2 id="ce-qui-sest-passe">Ce qui s’est passé</h2>
<dl>
diff --git a/feeds/all-en.atom.xml b/feeds/all-en.atom.xml
index d4d7ad7..d8ada15 100644
--- a/feeds/all-en.atom.xml
+++ b/feeds/all-en.atom.xml
@@ -1,51 +1,62 @@
Alexis Métaireau https://blog.notmyidea.org/ 2023-10-11T00:00:00+02:00 Convert string to duration 2023-10-11T00:00:00+02:00 2023-10-11T00:00:00+02:00 tag:blog.notmyidea.org,2023-10-11:/convert-string-to-duration.html <p>I found myself wanting to convert a string to a duration (int), for some configuration.</p>
<p>Something you can call like this:</p>
-<div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"days"</span><span class="p">)</span> <span class="c1"># returns 1</span>
-<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span> <span class="c1"># returns 24</span>
-<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span> <span class="c1"># returns 3 * 24 * 30</span>
+<div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"days"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"minutes"</span><span class="p">)</span>
</code></pre></div>
<p>The code :</p>
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span>
-
-<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value …</span></code></pre></div> <p>I found myself wanting to convert a string to a duration (int), for some configuration.</p>
+<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span> <span class="n">Literal</span><span class="p">[</span><span class="s2">"days …</span></code></pre></div> <p>I found myself wanting to convert a string to a duration (int), for some configuration.</p>
<p>Something you can call like this:</p>
-<div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"days"</span><span class="p">)</span> <span class="c1"># returns 1</span>
-<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span> <span class="c1"># returns 24</span>
-<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span> <span class="c1"># returns 3 * 24 * 30</span>
+<div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"days"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"minutes"</span><span class="p">)</span>
</code></pre></div>
<p>The code :</p>
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span>
-
-<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span> <span class="n">Literal</span><span class="p">[</span><span class="s2">"days"</span><span class="p">,</span> <span class="s2">"hours"</span><span class="p">]):</span>
-<span class="w"> </span><span class="sd">"""Convert a string to a number of hours, or days"""</span>
+<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span> <span class="n">Literal</span><span class="p">[</span><span class="s2">"days"</span><span class="p">,</span> <span class="s2">"hours"</span><span class="p">,</span> <span class="s2">"minutes"</span><span class="p">]):</span>
+<span class="w"> </span><span class="sd">"""Convert a string to a number of hours, days or minutes"""</span>
<span class="n">num</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="s2">""</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">filter</span><span class="p">(</span><span class="nb">str</span><span class="o">.</span><span class="n">isdigit</span><span class="p">,</span> <span class="n">value</span><span class="p">)))</span>
- <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"hours"</span><span class="p">:</span>
- <span class="n">reconvert</span> <span class="o">=</span> <span class="kc">True</span>
+ <span class="c1"># It's not possible to convert from a smaller unit to a greater one:</span>
+ <span class="c1"># - hours and minutes cannot be converted to days</span>
+ <span class="c1"># - minutes cannot be converted to hours</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">target</span> <span class="o">==</span> <span class="s2">"days"</span> <span class="ow">and</span> <span class="p">(</span><span class="s2">"h"</span> <span class="ow">in</span> <span class="n">value</span> <span class="ow">or</span> <span class="s2">"m"</span> <span class="ow">in</span> <span class="n">value</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">"mo"</span><span class="p">,</span> <span class="s2">""</span><span class="p">)))</span> <span class="ow">or</span> <span class="p">(</span>
+ <span class="n">target</span> <span class="o">==</span> <span class="s2">"hours"</span> <span class="ow">and</span> <span class="s2">"m"</span> <span class="ow">in</span> <span class="n">value</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">"mo"</span><span class="p">,</span> <span class="s2">""</span><span class="p">)</span>
+ <span class="p">):</span>
+ <span class="n">msg</span> <span class="o">=</span> <span class="p">(</span>
+ <span class="s2">"Durations cannot be converted from a smaller to a greater unit. "</span>
+ <span class="sa">f</span><span class="s2">"(trying to convert '</span><span class="si">{</span><span class="n">value</span><span class="si">}</span><span class="s2">' to </span><span class="si">{</span><span class="n">target</span><span class="si">}</span><span class="s2">)"</span>
+ <span class="p">)</span>
+ <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
+ <span class="c1"># Consider we're converting to minutes, do the eventual multiplication at the end.</span>
<span class="k">if</span> <span class="s2">"h"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"days"</span><span class="p">:</span>
- <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"Invalid duration value"</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span>
- <span class="n">reconvert</span> <span class="o">=</span> <span class="kc">False</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span>
<span class="k">elif</span> <span class="s2">"d"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span>
<span class="k">elif</span> <span class="s2">"w"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">7</span>
- <span class="k">elif</span> <span class="s2">"m"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">30</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span> <span class="o">*</span> <span class="mi">7</span>
+ <span class="k">elif</span> <span class="s2">"mo"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span> <span class="o">*</span> <span class="mi">30</span> <span class="c1"># considers 30d in a month</span>
<span class="k">elif</span> <span class="s2">"y"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">365</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span> <span class="o">*</span> <span class="mi">365</span>
+ <span class="k">elif</span> <span class="s2">"m"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"Invalid duration value"</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
- <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"hours"</span> <span class="ow">and</span> <span class="n">reconvert</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">24</span>
+ <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"hours"</span><span class="p">:</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">/</span> <span class="mi">60</span>
+ <span class="k">elif</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"days"</span><span class="p">:</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">/</span> <span class="mi">60</span> <span class="o">/</span> <span class="mi">24</span>
<span class="k">return</span> <span class="n">num</span>
</code></pre></div> 2023, Semaine 40 2023-10-08T00:00:00+02:00 2023-10-08T00:00:00+02:00 tag:blog.notmyidea.org,2023-10-08:/2023-semaine-40.html
diff --git a/feeds/all.atom.xml b/feeds/all.atom.xml
index 74bd02a..8f13dc5 100644
--- a/feeds/all.atom.xml
+++ b/feeds/all.atom.xml
@@ -1,51 +1,62 @@
Alexis Métaireau https://blog.notmyidea.org/ 2023-10-11T00:00:00+02:00 Convert string to duration 2023-10-11T00:00:00+02:00 2023-10-11T00:00:00+02:00 tag:blog.notmyidea.org,2023-10-11:/convert-string-to-duration.html <p>I found myself wanting to convert a string to a duration (int), for some configuration.</p>
<p>Something you can call like this:</p>
-<div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"days"</span><span class="p">)</span> <span class="c1"># returns 1</span>
-<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span> <span class="c1"># returns 24</span>
-<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span> <span class="c1"># returns 3 * 24 * 30</span>
+<div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"days"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"minutes"</span><span class="p">)</span>
</code></pre></div>
<p>The code :</p>
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span>
-
-<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value …</span></code></pre></div> <p>I found myself wanting to convert a string to a duration (int), for some configuration.</p>
+<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span> <span class="n">Literal</span><span class="p">[</span><span class="s2">"days …</span></code></pre></div> <p>I found myself wanting to convert a string to a duration (int), for some configuration.</p>
<p>Something you can call like this:</p>
-<div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"days"</span><span class="p">)</span> <span class="c1"># returns 1</span>
-<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span> <span class="c1"># returns 24</span>
-<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span> <span class="c1"># returns 3 * 24 * 30</span>
+<div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"days"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"minutes"</span><span class="p">)</span>
</code></pre></div>
<p>The code :</p>
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span>
-
-<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span> <span class="n">Literal</span><span class="p">[</span><span class="s2">"days"</span><span class="p">,</span> <span class="s2">"hours"</span><span class="p">]):</span>
-<span class="w"> </span><span class="sd">"""Convert a string to a number of hours, or days"""</span>
+<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span> <span class="n">Literal</span><span class="p">[</span><span class="s2">"days"</span><span class="p">,</span> <span class="s2">"hours"</span><span class="p">,</span> <span class="s2">"minutes"</span><span class="p">]):</span>
+<span class="w"> </span><span class="sd">"""Convert a string to a number of hours, days or minutes"""</span>
<span class="n">num</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="s2">""</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">filter</span><span class="p">(</span><span class="nb">str</span><span class="o">.</span><span class="n">isdigit</span><span class="p">,</span> <span class="n">value</span><span class="p">)))</span>
- <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"hours"</span><span class="p">:</span>
- <span class="n">reconvert</span> <span class="o">=</span> <span class="kc">True</span>
+ <span class="c1"># It's not possible to convert from a smaller unit to a greater one:</span>
+ <span class="c1"># - hours and minutes cannot be converted to days</span>
+ <span class="c1"># - minutes cannot be converted to hours</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">target</span> <span class="o">==</span> <span class="s2">"days"</span> <span class="ow">and</span> <span class="p">(</span><span class="s2">"h"</span> <span class="ow">in</span> <span class="n">value</span> <span class="ow">or</span> <span class="s2">"m"</span> <span class="ow">in</span> <span class="n">value</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">"mo"</span><span class="p">,</span> <span class="s2">""</span><span class="p">)))</span> <span class="ow">or</span> <span class="p">(</span>
+ <span class="n">target</span> <span class="o">==</span> <span class="s2">"hours"</span> <span class="ow">and</span> <span class="s2">"m"</span> <span class="ow">in</span> <span class="n">value</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">"mo"</span><span class="p">,</span> <span class="s2">""</span><span class="p">)</span>
+ <span class="p">):</span>
+ <span class="n">msg</span> <span class="o">=</span> <span class="p">(</span>
+ <span class="s2">"Durations cannot be converted from a smaller to a greater unit. "</span>
+ <span class="sa">f</span><span class="s2">"(trying to convert '</span><span class="si">{</span><span class="n">value</span><span class="si">}</span><span class="s2">' to </span><span class="si">{</span><span class="n">target</span><span class="si">}</span><span class="s2">)"</span>
+ <span class="p">)</span>
+ <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
+ <span class="c1"># Consider we're converting to minutes, do the eventual multiplication at the end.</span>
<span class="k">if</span> <span class="s2">"h"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"days"</span><span class="p">:</span>
- <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"Invalid duration value"</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span>
- <span class="n">reconvert</span> <span class="o">=</span> <span class="kc">False</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span>
<span class="k">elif</span> <span class="s2">"d"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span>
<span class="k">elif</span> <span class="s2">"w"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">7</span>
- <span class="k">elif</span> <span class="s2">"m"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">30</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span> <span class="o">*</span> <span class="mi">7</span>
+ <span class="k">elif</span> <span class="s2">"mo"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span> <span class="o">*</span> <span class="mi">30</span> <span class="c1"># considers 30d in a month</span>
<span class="k">elif</span> <span class="s2">"y"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">365</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span> <span class="o">*</span> <span class="mi">365</span>
+ <span class="k">elif</span> <span class="s2">"m"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"Invalid duration value"</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
- <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"hours"</span> <span class="ow">and</span> <span class="n">reconvert</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">24</span>
+ <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"hours"</span><span class="p">:</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">/</span> <span class="mi">60</span>
+ <span class="k">elif</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"days"</span><span class="p">:</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">/</span> <span class="mi">60</span> <span class="o">/</span> <span class="mi">24</span>
<span class="k">return</span> <span class="n">num</span>
</code></pre></div> 2023, Semaine 40 2023-10-08T00:00:00+02:00 2023-10-08T00:00:00+02:00 tag:blog.notmyidea.org,2023-10-08:/2023-semaine-40.html
diff --git a/feeds/code.atom.xml b/feeds/code.atom.xml
index 637306b..85b02b2 100644
--- a/feeds/code.atom.xml
+++ b/feeds/code.atom.xml
@@ -1,51 +1,62 @@
Alexis Métaireau - code https://blog.notmyidea.org/ 2023-10-11T00:00:00+02:00 Convert string to duration 2023-10-11T00:00:00+02:00 2023-10-11T00:00:00+02:00 tag:blog.notmyidea.org,2023-10-11:/convert-string-to-duration.html <p>I found myself wanting to convert a string to a duration (int), for some configuration.</p>
<p>Something you can call like this:</p>
-<div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"days"</span><span class="p">)</span> <span class="c1"># returns 1</span>
-<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span> <span class="c1"># returns 24</span>
-<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span> <span class="c1"># returns 3 * 24 * 30</span>
+<div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"days"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"minutes"</span><span class="p">)</span>
</code></pre></div>
<p>The code :</p>
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span>
-
-<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value …</span></code></pre></div> <p>I found myself wanting to convert a string to a duration (int), for some configuration.</p>
+<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span> <span class="n">Literal</span><span class="p">[</span><span class="s2">"days …</span></code></pre></div> <p>I found myself wanting to convert a string to a duration (int), for some configuration.</p>
<p>Something you can call like this:</p>
-<div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"days"</span><span class="p">)</span> <span class="c1"># returns 1</span>
-<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span> <span class="c1"># returns 24</span>
-<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span> <span class="c1"># returns 3 * 24 * 30</span>
+<div class="highlight"><pre><span></span><code><span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"days"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"1d"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"hours"</span><span class="p">)</span>
+<span class="n">string_to_duration</span><span class="p">(</span><span class="s2">"3m"</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">"minutes"</span><span class="p">)</span>
</code></pre></div>
<p>The code :</p>
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Literal</span>
-
-<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span> <span class="n">Literal</span><span class="p">[</span><span class="s2">"days"</span><span class="p">,</span> <span class="s2">"hours"</span><span class="p">]):</span>
-<span class="w"> </span><span class="sd">"""Convert a string to a number of hours, or days"""</span>
+<span class="k">def</span> <span class="nf">string_to_duration</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">target</span><span class="p">:</span> <span class="n">Literal</span><span class="p">[</span><span class="s2">"days"</span><span class="p">,</span> <span class="s2">"hours"</span><span class="p">,</span> <span class="s2">"minutes"</span><span class="p">]):</span>
+<span class="w"> </span><span class="sd">"""Convert a string to a number of hours, days or minutes"""</span>
<span class="n">num</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="s2">""</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">filter</span><span class="p">(</span><span class="nb">str</span><span class="o">.</span><span class="n">isdigit</span><span class="p">,</span> <span class="n">value</span><span class="p">)))</span>
- <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"hours"</span><span class="p">:</span>
- <span class="n">reconvert</span> <span class="o">=</span> <span class="kc">True</span>
+ <span class="c1"># It's not possible to convert from a smaller unit to a greater one:</span>
+ <span class="c1"># - hours and minutes cannot be converted to days</span>
+ <span class="c1"># - minutes cannot be converted to hours</span>
+ <span class="k">if</span> <span class="p">(</span><span class="n">target</span> <span class="o">==</span> <span class="s2">"days"</span> <span class="ow">and</span> <span class="p">(</span><span class="s2">"h"</span> <span class="ow">in</span> <span class="n">value</span> <span class="ow">or</span> <span class="s2">"m"</span> <span class="ow">in</span> <span class="n">value</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">"mo"</span><span class="p">,</span> <span class="s2">""</span><span class="p">)))</span> <span class="ow">or</span> <span class="p">(</span>
+ <span class="n">target</span> <span class="o">==</span> <span class="s2">"hours"</span> <span class="ow">and</span> <span class="s2">"m"</span> <span class="ow">in</span> <span class="n">value</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">"mo"</span><span class="p">,</span> <span class="s2">""</span><span class="p">)</span>
+ <span class="p">):</span>
+ <span class="n">msg</span> <span class="o">=</span> <span class="p">(</span>
+ <span class="s2">"Durations cannot be converted from a smaller to a greater unit. "</span>
+ <span class="sa">f</span><span class="s2">"(trying to convert '</span><span class="si">{</span><span class="n">value</span><span class="si">}</span><span class="s2">' to </span><span class="si">{</span><span class="n">target</span><span class="si">}</span><span class="s2">)"</span>
+ <span class="p">)</span>
+ <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
+ <span class="c1"># Consider we're converting to minutes, do the eventual multiplication at the end.</span>
<span class="k">if</span> <span class="s2">"h"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"days"</span><span class="p">:</span>
- <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"Invalid duration value"</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span>
- <span class="n">reconvert</span> <span class="o">=</span> <span class="kc">False</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span>
<span class="k">elif</span> <span class="s2">"d"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span>
<span class="k">elif</span> <span class="s2">"w"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">7</span>
- <span class="k">elif</span> <span class="s2">"m"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">30</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span> <span class="o">*</span> <span class="mi">7</span>
+ <span class="k">elif</span> <span class="s2">"mo"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span> <span class="o">*</span> <span class="mi">30</span> <span class="c1"># considers 30d in a month</span>
<span class="k">elif</span> <span class="s2">"y"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">365</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span> <span class="o">*</span> <span class="mi">365</span>
+ <span class="k">elif</span> <span class="s2">"m"</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"Invalid duration value"</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
- <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"hours"</span> <span class="ow">and</span> <span class="n">reconvert</span><span class="p">:</span>
- <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">*</span> <span class="mi">24</span>
+ <span class="k">if</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"hours"</span><span class="p">:</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">/</span> <span class="mi">60</span>
+ <span class="k">elif</span> <span class="n">target</span> <span class="o">==</span> <span class="s2">"days"</span><span class="p">:</span>
+ <span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">/</span> <span class="mi">60</span> <span class="o">/</span> <span class="mi">24</span>
<span class="k">return</span> <span class="n">num</span>
</code></pre></div> llm command-line tips 2023-09-27T00:00:00+02:00 2023-09-27T00:00:00+02:00 tag:blog.notmyidea.org,2023-09-27:/llm-command-line-tips.html <p>I’m using <a href="https://llm.datasette.io">llm</a> more and more, and today I had to find back prompts I used in the past. Here is a command I’ve been using, which allows me to filter the results based on what I want. It leverages <a href="https://sqlutils.datasette.io">sql-utils</a>, a cli tool which is able to …</p> <p>I’m using <a href="https://llm.datasette.io">llm</a> more and more, and today I had to find back prompts I used in the past. Here is a command I’ve been using, which allows me to filter the results based on what I want. It leverages <a href="https://sqlutils.datasette.io">sql-utils</a>, a cli tool which is able to talk to a <span class="caps">SQLITE</span> database and answer in json, and <a href="https://github.com/jqlang/jq">jq</a> a command-line tool capable of doing requests for json.</p>
diff --git a/tag/conversion.html b/tag/conversion.html
index a52c0d6..52f3f7e 100644
--- a/tag/conversion.html
+++ b/tag/conversion.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …
diff --git a/tag/python.html b/tag/python.html
index d1f2480..76090a9 100644
--- a/tag/python.html
+++ b/tag/python.html
@@ -31,16 +31,16 @@
python , conversion
I found myself wanting to convert a string to a duration (int), for some configuration.
Something you can call like this:
-string_to_duration ( "1d" , target = "days" ) # returns 1
-string_to_duration ( "1d" , target = "hours" ) # returns 24
-string_to_duration ( "3m" , target = "hours" ) # returns 3 * 24 * 30
+string_to_duration ( "1d" , target = "days" )
+string_to_duration ( "1d" , target = "hours" )
+string_to_duration ( "3m" , target = "hours" )
+string_to_duration ( "3m" , target = "minutes" )
The code :
from typing import Literal
-
-def string_to_duration ( value …
+def string_to_duration ( value : str , target : Literal [ "days …