To show the adding one month also, and to show, it's not only three, but 
sometime four day in a row, plus/minus one month, lead to the very same 
date, I've added a few lines to the java example:

import java.time.*;
 
public class Leaps {
    public static void main(String[] args)
    {
        LocalDate march28_23 = LocalDate.parse("2023-03-28");
        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("Minus:%n%n%s minus one month: %s%n", march28_23, 
march28_23.minusMonths(1));
        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("Leap year:%n%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));
        
        LocalDate jan28_23 = LocalDate.parse("2023-01-28");
        LocalDate jan29_23 = LocalDate.parse("2023-01-29");
        LocalDate jan30_23 = LocalDate.parse("2023-01-30");
        LocalDate jan31_23 = LocalDate.parse("2023-01-31");
        LocalDate jan29_24 = LocalDate.parse("2024-01-29");
        LocalDate jan30_24 = LocalDate.parse("2024-01-30");
        LocalDate jan31_24 = LocalDate.parse("2024-01-31");
 
        System.out.printf("%nPlus:%n%n%s plus one month: %s%n", jan28_23, 
jan28_23.plusMonths(1));
        System.out.printf("%s plus one month: %s%n", jan29_23, 
jan29_23.plusMonths(1));
        System.out.printf("%s plus one month: %s%n", jan30_23, 
jan30_23.plusMonths(1));
        System.out.printf("%s plus one month: %s%n", jan31_23, 
jan31_23.plusMonths(1));
        System.out.printf("Leap year:%n%s plus one month: %s%n", jan29_24, 
jan29_24.plusMonths(1));
        System.out.printf("%s plus one month: %s%n", jan30_24, 
jan30_24.plusMonths(1));
        System.out.printf("%s plus one month: %s%n", jan31_24, 
jan31_24.plusMonths(1));
    }
}

Output:

Minus:

2023-03-28 minus one month: 2023-02-28
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
Leap year:
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

Plus:

2023-01-28 plus one month: 2023-02-28
2023-01-29 plus one month: 2023-02-28
2023-01-30 plus one month: 2023-02-28
2023-01-31 plus one month: 2023-02-28
Leap year:
2024-01-29 plus one month: 2024-02-29
2024-01-30 plus one month: 2024-02-29
2024-01-31 plus one month: 2024-02-29 

Tom Keffer schrieb am Freitag, 1. März 2024 um 13:46:46 UTC+1:

> 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 '[email protected]' via weewx-user <
> [email protected]> 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 <[email protected]> 
>>> 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 <[email protected]> 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 <[email protected]> 
>>>>> 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 <[email protected]> 
>>>>>> 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 <
>>>>>>> [email protected]> 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 [email protected].
>>>>>>>> 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 
>>>>>>> [email protected].
>>>>>>> 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 [email protected].
>>>>>> 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 
>>>>> [email protected].
>>>>> 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 [email protected].
>>>>
>>> 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 [email protected].
>>
> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/4bb01398-b65d-486e-bd29-ce711300b6e4n%40googlegroups.com.

Reply via email to