That's interesting! However, Python treats it differently. The equivalent
would be something like

import datetime
march29_23 = datetime.date.fromisoformat("2023-03-29")
print(march29_23 - datetime.timedelta(month=1))


Unfortunately, datetime.timedelta does not offer an argument "month",
perhaps for just this reason.

However, I am open to a pull request should someone want to capture an
alternative behavior.

-tk



On Fri, Mar 1, 2024 at 1:13 AM 'michael.k...@gmx.at' via weewx-user <
weewx-user@googlegroups.com> wrote:

> Citing issue #436 <https://github.com/weewx/weewx/issues/436>
>
> "What is 30 March minus one month? By this solution, it should be 28 Feb.
>
> So then what is 29 March minus one month? Also 28 Feb? And so would 28
> March minus a month. So, "one month earlier" for three days in a row leads
> to the same date. That doesn't seem right."
> That's how the Java People do it:
> import java.time.*;
>
> import java.time.*;
>
> public class Leaps {
>     public static void main(String[] args)
>     {
>         LocalDate march29_23 = LocalDate.parse("2023-03-29");
>         LocalDate march30_23 = LocalDate.parse("2023-03-30");
>         LocalDate march31_23 = LocalDate.parse("2023-03-31");
>         LocalDate march29_24 = LocalDate.parse("2024-03-29");
>         LocalDate march30_24 = LocalDate.parse("2024-03-30");
>         LocalDate march31_24 = LocalDate.parse("2024-03-31");
>
>         System.out.printf("%s minus one month: %s%n", march29_23,
> march29_23.minusMonths(1));
>         System.out.printf("%s minus one month: %s%n", march30_23,
> march30_23.minusMonths(1));
>         System.out.printf("%s minus one month: %s%n", march31_23,
> march31_23.minusMonths(1));
>         System.out.printf("%s minus one month: %s%n", march29_24,
> march29_24.minusMonths(1));
>         System.out.printf("%s minus one month: %s%n", march30_24,
> march30_24.minusMonths(1));
>         System.out.printf("%s minus one month: %s%n", march31_24,
> march31_24.minusMonths(1));
>     }
> }
>
> Output:
> 2023-03-29 minus one month: 2023-02-28
> 2023-03-30 minus one month: 2023-02-28
> 2023-03-31 minus one month: 2023-02-28
> 2024-03-29 minus one month: 2024-02-29
> 2024-03-30 minus one month: 2024-02-29
> 2024-03-31 minus one month: 2024-02-29
>
> So, they claim it is right, what doesn't seem right for you.
> Tom Keffer schrieb am Donnerstag, 29. Februar 2024 um 21:03:55 UTC+1:
>
>> I am not surprised that $year_delta=1 does not work on leap day. There is
>> no 29 February 2023.
>>
>> This is issue #436 <https://github.com/weewx/weewx/issues/436>.
>>
>>
>> On Thu, Feb 29, 2024 at 9:45 AM František Slimařík <xsli...@gmail.com>
>> wrote:
>>
>>> Hi Tom,
>>>
>>> actually I found another for cycle which caused the issue. When I
>>> changed delta from "$year_delta=1" into "$day_delta=365" it works again.
>>> Interesting it worked without any issue till yesterday :)
>>>
>>> ##for $A in $span($year_delta=1).months
>>>          $A.dateTime.format("%OB %Y");$A.rain.sum.format(add_label=False)
>>> #end for
>>>
>>>
>>> čt 29. 2. 2024 v 15:49 odesílatel Tom Keffer <tke...@gmail.com> napsal:
>>>
>>>> I just tried this and it worked fine:
>>>>
>>>> 28. February 2023;33.4
>>>> 1. March 2023;36.1
>>>> 2. March 2023;38.0
>>>> 3. March 2023;37.1
>>>> ...
>>>> 26. February 2024;37.3
>>>> 27. February 2024;38.5
>>>> 28. February 2024;41.3
>>>>
>>>>
>>>> On Wed, Feb 28, 2024 at 8:57 PM František Slimařík <xsli...@gmail.com>
>>>> wrote:
>>>>
>>>>> Yes, right
>>>>>
>>>>> #for $i in $span($day_delta=365).days
>>>>> #set fDate = $i.dateTime.format("%-d. %B %Y")
>>>>> $fDate;$i.outTemp.avg.format(add_label=False)
>>>>> #end for
>>>>>
>>>>> čt 29. 2. 2024 v 1:49 odesílatel Tom Keffer <tke...@gmail.com> napsal:
>>>>>
>>>>>> I don't know. How are you using the $span() tags? In a loop, I assume?
>>>>>>
>>>>>> On Wed, Feb 28, 2024 at 3:25 PM František Slimařík <xsli...@gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>>> Hello,
>>>>>>>
>>>>>>> is it possible that leap year causes issue in span tag? I am using
>>>>>>> these:
>>>>>>>
>>>>>>> $span($day_delta=365).days
>>>>>>> $span($year_delta=1).months
>>>>>>>
>>>>>>> Feb 29 00:10:43 rocky-weather-machine weewxd[405028]: ERROR
>>>>>>> weewx.cheetahgenerator: Evaluation of template
>>>>>>> /etc/weewx/skins/neowx/year.html.tmpl failed with exception '<class
>>>>>>> 'ValueError'>'
>>>>>>> Feb 29 00:10:43 rocky-weather-machine weewxd[405028]: ERROR
>>>>>>> weewx.cheetahgenerator: **** Ignoring template
>>>>>>> /etc/weewx/skins/neowx/year.html.tmpl
>>>>>>> Feb 29 00:10:43 rocky-weather-machine weewxd[405028]: ERROR
>>>>>>> weewx.cheetahgenerator: **** Reason: day is out of range for month
>>>>>>> Feb 29 00:10:43 rocky-weather-machine weewxd[405028]: ERROR
>>>>>>> weewx.cheetahgenerator: ****  Traceback (most recent call last):
>>>>>>> Feb 29 00:10:43 rocky-weather-machine weewxd[405028]: ERROR
>>>>>>> weewx.cheetahgenerator: ****    File
>>>>>>> "/usr/share/weewx/weewx/cheetahgenerator.py", line 334, in generate
>>>>>>> Feb 29 00:10:43 rocky-weather-machine weewxd[405028]: ERROR
>>>>>>> weewx.cheetahgenerator: ****      unicode_string =
>>>>>>> compiled_template.respond()
>>>>>>> Feb 29 00:10:43 rocky-weather-machine weewxd[405028]: ERROR
>>>>>>> weewx.cheetahgenerator: ****    File
>>>>>>> "_etc_weewx_skins_neowx_year_html_tmpl.py", line 1380, in respond
>>>>>>> Feb 29 00:10:43 rocky-weather-machine weewxd[405028]: ERROR
>>>>>>> weewx.cheetahgenerator: ****    File "/usr/share/weewx/weewx/tags.py", 
>>>>>>> line
>>>>>>> 132, in span
>>>>>>> Feb 29 00:10:43 rocky-weather-machine weewxd[405028]: ERROR
>>>>>>> weewx.cheetahgenerator: ****      year_delta=year_delta, 
>>>>>>> boundary=boundary),
>>>>>>> Feb 29 00:10:43 rocky-weather-machine weewxd[405028]: ERROR
>>>>>>> weewx.cheetahgenerator: ****    File 
>>>>>>> "/usr/share/weewx/weeutil/weeutil.py",
>>>>>>> line 402, in archiveSpanSpan
>>>>>>> Feb 29 00:10:43 rocky-weather-machine weewxd[405028]: ERROR
>>>>>>> weewx.cheetahgenerator: ****      start_dt = time_dt.replace(year=year,
>>>>>>> month=month)
>>>>>>> Feb 29 00:10:43 rocky-weather-machine weewxd[405028]: ERROR
>>>>>>> weewx.cheetahgenerator: ****  ValueError: day is out of range for month
>>>>>>>
>>>>>>> --
>>>>>>> You received this message because you are subscribed to the Google
>>>>>>> Groups "weewx-user" group.
>>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>>> send an email to weewx-user+...@googlegroups.com.
>>>>>>> To view this discussion on the web visit
>>>>>>> https://groups.google.com/d/msgid/weewx-user/6ca52acb-9235-4154-9e01-ba5e23a9750dn%40googlegroups.com
>>>>>>> <https://groups.google.com/d/msgid/weewx-user/6ca52acb-9235-4154-9e01-ba5e23a9750dn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>>> .
>>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to a topic in
>>>>>> the Google Groups "weewx-user" group.
>>>>>> To unsubscribe from this topic, visit
>>>>>> https://groups.google.com/d/topic/weewx-user/7c8sNahwkiw/unsubscribe.
>>>>>> To unsubscribe from this group and all its topics, send an email to
>>>>>> weewx-user+...@googlegroups.com.
>>>>>> To view this discussion on the web visit
>>>>>> https://groups.google.com/d/msgid/weewx-user/CAPq0zECBN016YJK8gbzfY_gM4rjGFxmFUDmjpHWEdGcfTH2Tog%40mail.gmail.com
>>>>>> <https://groups.google.com/d/msgid/weewx-user/CAPq0zECBN016YJK8gbzfY_gM4rjGFxmFUDmjpHWEdGcfTH2Tog%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "weewx-user" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to weewx-user+...@googlegroups.com.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/weewx-user/CAPXATBW0bD_xgqW9m0q0yQ2JzoFB3uJmJv77ARyzM_dF-4ajOQ%40mail.gmail.com
>>>>> <https://groups.google.com/d/msgid/weewx-user/CAPXATBW0bD_xgqW9m0q0yQ2JzoFB3uJmJv77ARyzM_dF-4ajOQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>> --
>>>> You received this message because you are subscribed to a topic in the
>>>> Google Groups "weewx-user" group.
>>>> To unsubscribe from this topic, visit
>>>> https://groups.google.com/d/topic/weewx-user/7c8sNahwkiw/unsubscribe.
>>>> To unsubscribe from this group and all its topics, send an email to
>>>> weewx-user+...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/weewx-user/CAPq0zEABFqb9wgJyMprjwLga5%2BoiF3YvVO35VhvxoO7HT5NjjA%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/weewx-user/CAPq0zEABFqb9wgJyMprjwLga5%2BoiF3YvVO35VhvxoO7HT5NjjA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "weewx-user" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to weewx-user+...@googlegroups.com.
>>>
>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/weewx-user/CAPXATBXy019RDT-S_1HN6gApoyDxhtPP8Ay_%3DuQS6R87nHjiGQ%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/weewx-user/CAPXATBXy019RDT-S_1HN6gApoyDxhtPP8Ay_%3DuQS6R87nHjiGQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "weewx-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to weewx-user+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/weewx-user/9ebffa35-d075-4c64-87c4-7d41a99f4673n%40googlegroups.com
> <https://groups.google.com/d/msgid/weewx-user/9ebffa35-d075-4c64-87c4-7d41a99f4673n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to weewx-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/CAPq0zEC_WN5qkVPwXi2sMNDGSR2%2B110xSj9uw3Tc%2BQ3-67w-OA%40mail.gmail.com.

Reply via email to