leap year and span

140 weergaven
Naar het eerste ongelezen bericht

František Slimařík

ongelezen,
28 feb 2024, 18:25:0928 feb
aan weewx-user
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

Tom Keffer

ongelezen,
28 feb 2024, 19:49:3628 feb
aan weewx...@googlegroups.com
I don't know. How are you using the $span() tags? In a loop, I assume?

--
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.

František Slimařík

ongelezen,
28 feb 2024, 23:57:3528 feb
aan weewx...@googlegroups.com
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:
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.

Tom Keffer

ongelezen,
29 feb 2024, 09:49:4929 feb
aan weewx...@googlegroups.com
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


František Slimařík

ongelezen,
29 feb 2024, 12:45:3629 feb
aan weewx...@googlegroups.com
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:

Tom Keffer

ongelezen,
29 feb 2024, 15:03:5529 feb
aan weewx...@googlegroups.com
I am not surprised that $year_delta=1 does not work on leap day. There is no 29 February 2023.

This is issue #436.


michael.k...@gmx.at

ongelezen,
1 mrt 2024, 04:12:591 mrt
aan weewx-user
Citing issue #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. 

Graham Eddy

ongelezen,
1 mrt 2024, 07:41:001 mrt
aan WeeWX User
“month” is a fuzzy measure, not precise. it is not surprising that arithmetic with fuzzy numbers produces fuzzy numbers.
what *is* surprising is that people find the above surprising

same as network distributed time - given the variable time it takes to transfer a “time” to another place, we all agree that two such “time” values are considered “equal” if their difference is within a workable tolerance.
⊣GE⊢

Tom Keffer

ongelezen,
1 mrt 2024, 07:46:461 mrt
aan weewx...@googlegroups.com
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



michael.k...@gmx.at

ongelezen,
1 mrt 2024, 12:38:461 mrt
aan weewx-user
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 

Allen beantwoorden
Auteur beantwoorden
Doorsturen
0 nieuwe berichten