Why does java.time.Period#normalized() not normalize days?What is reflection and why is it useful?Does a finally block always get executed in Java?What is a serialVersionUID and why should I use it?Why does Java have transient fields?Why is subtracting these two times (in 1927) giving a strange result?Why don't Java's +=, -=, *=, /= compound assignment operators require casting?Why is char[] preferred over String for passwords?Why is processing a sorted array faster than processing an unsorted array?Why does this code using random strings print “hello world”?Why is printing “B” dramatically slower than printing “#”?

Construct a pentagon avoiding compass use

Create dashed intersections with labels using pgfplots and tikz

Optimizing Process Builder: Early Exit: Worthwhile?

Help with understanding nuances of extremely popular Kyoto-ben (?) tweet

Can a continent naturally split into two distant parts within a week?

Interpreting the word "randomly"

Installing ubuntu with HD + SSD

What does "Fotze" really mean?

Dropping outliers based on "2.5 times the RMSE"

Modeling, view and projection transformation using vector and point in homogenous form

What would be the ideal melee weapon made of "Phase Metal"?

Why does the autopilot disengage even when it does not receive pilot input?

Why hasn't the U.S. government paid war reparations to any country it attacked?

How can an advanced civilization forget how to manufacture its technology?

Can I intentionally omit previous work experience or pretend it doesn't exist when applying for jobs?

Players of unusual orchestral instruments

In which ways do anagamis still experience ignorance?

When did the Roman Empire fall according to contemporaries?

Is purchasing foreign currency before going abroad a losing proposition?

Should you avoid redundant information after dialogue?

How to repair a laptop's screen hinges?

What is the English equivalent of 干物女 (dried fish woman)?

How do I write a romance that doesn't look obvious

Filtering fine silt/mud from water (not necessarily bacteria etc.)



Why does java.time.Period#normalized() not normalize days?


What is reflection and why is it useful?Does a finally block always get executed in Java?What is a serialVersionUID and why should I use it?Why does Java have transient fields?Why is subtracting these two times (in 1927) giving a strange result?Why don't Java's +=, -=, *=, /= compound assignment operators require casting?Why is char[] preferred over String for passwords?Why is processing a sorted array faster than processing an unsorted array?Why does this code using random strings print “hello world”?Why is printing “B” dramatically slower than printing “#”?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








8















In the Java class java.time.Period the method normalized() has the following in its Javadoc:




This normalizes the years and months units, leaving the days unit unchanged.




The superclass' method has the following in its Javadoc:




The process of normalization is specific to each calendar system. For example, in the ISO calendar system, the years and months are normalized but the days are not, [...]




I do not have access to the actual text of ISO 8601-1:2019, and would not like to spend hundreds of [insert currency here]s on it (my guess is that normalization may be described in Part 1: Basic rules and not in Part 2: Extensions).



Could someone shed light upon why Period#normalized() does not normalize days? Does it really come directly from ISO 8601 itself, is it somewhere else specified, or is it just specific to the Java implementation?










share|improve this question
























  • @Zabuza: I'm familiar with the Wikipedia page, however, it does not cover normalization of dates/periods.

    – D. Kovács
    9 hours ago

















8















In the Java class java.time.Period the method normalized() has the following in its Javadoc:




This normalizes the years and months units, leaving the days unit unchanged.




The superclass' method has the following in its Javadoc:




The process of normalization is specific to each calendar system. For example, in the ISO calendar system, the years and months are normalized but the days are not, [...]




I do not have access to the actual text of ISO 8601-1:2019, and would not like to spend hundreds of [insert currency here]s on it (my guess is that normalization may be described in Part 1: Basic rules and not in Part 2: Extensions).



Could someone shed light upon why Period#normalized() does not normalize days? Does it really come directly from ISO 8601 itself, is it somewhere else specified, or is it just specific to the Java implementation?










share|improve this question
























  • @Zabuza: I'm familiar with the Wikipedia page, however, it does not cover normalization of dates/periods.

    – D. Kovács
    9 hours ago













8












8








8








In the Java class java.time.Period the method normalized() has the following in its Javadoc:




This normalizes the years and months units, leaving the days unit unchanged.




The superclass' method has the following in its Javadoc:




The process of normalization is specific to each calendar system. For example, in the ISO calendar system, the years and months are normalized but the days are not, [...]




I do not have access to the actual text of ISO 8601-1:2019, and would not like to spend hundreds of [insert currency here]s on it (my guess is that normalization may be described in Part 1: Basic rules and not in Part 2: Extensions).



Could someone shed light upon why Period#normalized() does not normalize days? Does it really come directly from ISO 8601 itself, is it somewhere else specified, or is it just specific to the Java implementation?










share|improve this question
















In the Java class java.time.Period the method normalized() has the following in its Javadoc:




This normalizes the years and months units, leaving the days unit unchanged.




The superclass' method has the following in its Javadoc:




The process of normalization is specific to each calendar system. For example, in the ISO calendar system, the years and months are normalized but the days are not, [...]




I do not have access to the actual text of ISO 8601-1:2019, and would not like to spend hundreds of [insert currency here]s on it (my guess is that normalization may be described in Part 1: Basic rules and not in Part 2: Extensions).



Could someone shed light upon why Period#normalized() does not normalize days? Does it really come directly from ISO 8601 itself, is it somewhere else specified, or is it just specific to the Java implementation?







java datetime java-time iso8601 period






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 8 hours ago









Basil Bourque

127k36 gold badges427 silver badges600 bronze badges




127k36 gold badges427 silver badges600 bronze badges










asked 9 hours ago









D. KovácsD. Kovács

8255 silver badges19 bronze badges




8255 silver badges19 bronze badges












  • @Zabuza: I'm familiar with the Wikipedia page, however, it does not cover normalization of dates/periods.

    – D. Kovács
    9 hours ago

















  • @Zabuza: I'm familiar with the Wikipedia page, however, it does not cover normalization of dates/periods.

    – D. Kovács
    9 hours ago
















@Zabuza: I'm familiar with the Wikipedia page, however, it does not cover normalization of dates/periods.

– D. Kovács
9 hours ago





@Zabuza: I'm familiar with the Wikipedia page, however, it does not cover normalization of dates/periods.

– D. Kovács
9 hours ago












1 Answer
1






active

oldest

votes


















9














This is because a period of years or months is always the same amount of time (the same period) for any given date. A year is always 12 months, 12 months are always a year, thus these parts of the period can easily be normalized.



However days are variable in relation to months and years. If you have a period of 1 year, 1 month and 32 days, you cannot normalize this to 1 year, 2 months and then a fixed amount of days, because it might be 1 day, 2 days, 3 days or 4 days, depending on which date you will apply the period on.



A month can be 28, 29, 30 or 31 days. A year can be 365 or 366 days. And since a period is independent of any fixed date, there is no way to decide these relations.



Example:




2019-01-01 + 01-01-32 is 2020-03-04



2020-01-01 + 01-01-32 is 2021-03-03



2020-02-01 + 01-01-32 is 2021-04-02



2020-03-01 + 01-01-32 is 2021-05-03




As you can see the days resulting from applying the same period to different dates varies depending on the month and on if it's a leap year.



Thus it is impossible to normalize days in a period and the days are not touched when normalizing.






share|improve this answer


















  • 1





    That makes sense. But this means, that the "day" part of a Period can be anything between Integer.MIN_VALUE and Integer.MAX_VALUE making some quite interesting constellations possible even after normalization, right? (I.e., if your API accepts Period objects, you must essentially sanity-check them?)

    – D. Kovács
    8 hours ago











  • Yeah, they can take any value. I don't see why that needs to be sanitized. A period of 500000 days is a valid period, why wouldn't it be?

    – Max Vollmer
    8 hours ago











  • Against malicious input... theoretical API for settings validity of max 2 years accepts a Period. Malicious input is 0 years, 1 month, 3650 days. You normalize and check year <= 2 and months accordingly. Yet, you set 10 years and a 1 month. (I know, it's a stretch, but you get the idea.)

    – D. Kovács
    8 hours ago






  • 1





    I would check the date I get as a result from using the period, not the period itself. But I guess it really depends on what the API is actually doing.

    – Max Vollmer
    7 hours ago











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f57021385%2fwhy-does-java-time-periodnormalized-not-normalize-days%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









9














This is because a period of years or months is always the same amount of time (the same period) for any given date. A year is always 12 months, 12 months are always a year, thus these parts of the period can easily be normalized.



However days are variable in relation to months and years. If you have a period of 1 year, 1 month and 32 days, you cannot normalize this to 1 year, 2 months and then a fixed amount of days, because it might be 1 day, 2 days, 3 days or 4 days, depending on which date you will apply the period on.



A month can be 28, 29, 30 or 31 days. A year can be 365 or 366 days. And since a period is independent of any fixed date, there is no way to decide these relations.



Example:




2019-01-01 + 01-01-32 is 2020-03-04



2020-01-01 + 01-01-32 is 2021-03-03



2020-02-01 + 01-01-32 is 2021-04-02



2020-03-01 + 01-01-32 is 2021-05-03




As you can see the days resulting from applying the same period to different dates varies depending on the month and on if it's a leap year.



Thus it is impossible to normalize days in a period and the days are not touched when normalizing.






share|improve this answer


















  • 1





    That makes sense. But this means, that the "day" part of a Period can be anything between Integer.MIN_VALUE and Integer.MAX_VALUE making some quite interesting constellations possible even after normalization, right? (I.e., if your API accepts Period objects, you must essentially sanity-check them?)

    – D. Kovács
    8 hours ago











  • Yeah, they can take any value. I don't see why that needs to be sanitized. A period of 500000 days is a valid period, why wouldn't it be?

    – Max Vollmer
    8 hours ago











  • Against malicious input... theoretical API for settings validity of max 2 years accepts a Period. Malicious input is 0 years, 1 month, 3650 days. You normalize and check year <= 2 and months accordingly. Yet, you set 10 years and a 1 month. (I know, it's a stretch, but you get the idea.)

    – D. Kovács
    8 hours ago






  • 1





    I would check the date I get as a result from using the period, not the period itself. But I guess it really depends on what the API is actually doing.

    – Max Vollmer
    7 hours ago
















9














This is because a period of years or months is always the same amount of time (the same period) for any given date. A year is always 12 months, 12 months are always a year, thus these parts of the period can easily be normalized.



However days are variable in relation to months and years. If you have a period of 1 year, 1 month and 32 days, you cannot normalize this to 1 year, 2 months and then a fixed amount of days, because it might be 1 day, 2 days, 3 days or 4 days, depending on which date you will apply the period on.



A month can be 28, 29, 30 or 31 days. A year can be 365 or 366 days. And since a period is independent of any fixed date, there is no way to decide these relations.



Example:




2019-01-01 + 01-01-32 is 2020-03-04



2020-01-01 + 01-01-32 is 2021-03-03



2020-02-01 + 01-01-32 is 2021-04-02



2020-03-01 + 01-01-32 is 2021-05-03




As you can see the days resulting from applying the same period to different dates varies depending on the month and on if it's a leap year.



Thus it is impossible to normalize days in a period and the days are not touched when normalizing.






share|improve this answer


















  • 1





    That makes sense. But this means, that the "day" part of a Period can be anything between Integer.MIN_VALUE and Integer.MAX_VALUE making some quite interesting constellations possible even after normalization, right? (I.e., if your API accepts Period objects, you must essentially sanity-check them?)

    – D. Kovács
    8 hours ago











  • Yeah, they can take any value. I don't see why that needs to be sanitized. A period of 500000 days is a valid period, why wouldn't it be?

    – Max Vollmer
    8 hours ago











  • Against malicious input... theoretical API for settings validity of max 2 years accepts a Period. Malicious input is 0 years, 1 month, 3650 days. You normalize and check year <= 2 and months accordingly. Yet, you set 10 years and a 1 month. (I know, it's a stretch, but you get the idea.)

    – D. Kovács
    8 hours ago






  • 1





    I would check the date I get as a result from using the period, not the period itself. But I guess it really depends on what the API is actually doing.

    – Max Vollmer
    7 hours ago














9












9








9







This is because a period of years or months is always the same amount of time (the same period) for any given date. A year is always 12 months, 12 months are always a year, thus these parts of the period can easily be normalized.



However days are variable in relation to months and years. If you have a period of 1 year, 1 month and 32 days, you cannot normalize this to 1 year, 2 months and then a fixed amount of days, because it might be 1 day, 2 days, 3 days or 4 days, depending on which date you will apply the period on.



A month can be 28, 29, 30 or 31 days. A year can be 365 or 366 days. And since a period is independent of any fixed date, there is no way to decide these relations.



Example:




2019-01-01 + 01-01-32 is 2020-03-04



2020-01-01 + 01-01-32 is 2021-03-03



2020-02-01 + 01-01-32 is 2021-04-02



2020-03-01 + 01-01-32 is 2021-05-03




As you can see the days resulting from applying the same period to different dates varies depending on the month and on if it's a leap year.



Thus it is impossible to normalize days in a period and the days are not touched when normalizing.






share|improve this answer













This is because a period of years or months is always the same amount of time (the same period) for any given date. A year is always 12 months, 12 months are always a year, thus these parts of the period can easily be normalized.



However days are variable in relation to months and years. If you have a period of 1 year, 1 month and 32 days, you cannot normalize this to 1 year, 2 months and then a fixed amount of days, because it might be 1 day, 2 days, 3 days or 4 days, depending on which date you will apply the period on.



A month can be 28, 29, 30 or 31 days. A year can be 365 or 366 days. And since a period is independent of any fixed date, there is no way to decide these relations.



Example:




2019-01-01 + 01-01-32 is 2020-03-04



2020-01-01 + 01-01-32 is 2021-03-03



2020-02-01 + 01-01-32 is 2021-04-02



2020-03-01 + 01-01-32 is 2021-05-03




As you can see the days resulting from applying the same period to different dates varies depending on the month and on if it's a leap year.



Thus it is impossible to normalize days in a period and the days are not touched when normalizing.







share|improve this answer












share|improve this answer



share|improve this answer










answered 9 hours ago









Max VollmerMax Vollmer

6,3745 gold badges21 silver badges38 bronze badges




6,3745 gold badges21 silver badges38 bronze badges







  • 1





    That makes sense. But this means, that the "day" part of a Period can be anything between Integer.MIN_VALUE and Integer.MAX_VALUE making some quite interesting constellations possible even after normalization, right? (I.e., if your API accepts Period objects, you must essentially sanity-check them?)

    – D. Kovács
    8 hours ago











  • Yeah, they can take any value. I don't see why that needs to be sanitized. A period of 500000 days is a valid period, why wouldn't it be?

    – Max Vollmer
    8 hours ago











  • Against malicious input... theoretical API for settings validity of max 2 years accepts a Period. Malicious input is 0 years, 1 month, 3650 days. You normalize and check year <= 2 and months accordingly. Yet, you set 10 years and a 1 month. (I know, it's a stretch, but you get the idea.)

    – D. Kovács
    8 hours ago






  • 1





    I would check the date I get as a result from using the period, not the period itself. But I guess it really depends on what the API is actually doing.

    – Max Vollmer
    7 hours ago













  • 1





    That makes sense. But this means, that the "day" part of a Period can be anything between Integer.MIN_VALUE and Integer.MAX_VALUE making some quite interesting constellations possible even after normalization, right? (I.e., if your API accepts Period objects, you must essentially sanity-check them?)

    – D. Kovács
    8 hours ago











  • Yeah, they can take any value. I don't see why that needs to be sanitized. A period of 500000 days is a valid period, why wouldn't it be?

    – Max Vollmer
    8 hours ago











  • Against malicious input... theoretical API for settings validity of max 2 years accepts a Period. Malicious input is 0 years, 1 month, 3650 days. You normalize and check year <= 2 and months accordingly. Yet, you set 10 years and a 1 month. (I know, it's a stretch, but you get the idea.)

    – D. Kovács
    8 hours ago






  • 1





    I would check the date I get as a result from using the period, not the period itself. But I guess it really depends on what the API is actually doing.

    – Max Vollmer
    7 hours ago








1




1





That makes sense. But this means, that the "day" part of a Period can be anything between Integer.MIN_VALUE and Integer.MAX_VALUE making some quite interesting constellations possible even after normalization, right? (I.e., if your API accepts Period objects, you must essentially sanity-check them?)

– D. Kovács
8 hours ago





That makes sense. But this means, that the "day" part of a Period can be anything between Integer.MIN_VALUE and Integer.MAX_VALUE making some quite interesting constellations possible even after normalization, right? (I.e., if your API accepts Period objects, you must essentially sanity-check them?)

– D. Kovács
8 hours ago













Yeah, they can take any value. I don't see why that needs to be sanitized. A period of 500000 days is a valid period, why wouldn't it be?

– Max Vollmer
8 hours ago





Yeah, they can take any value. I don't see why that needs to be sanitized. A period of 500000 days is a valid period, why wouldn't it be?

– Max Vollmer
8 hours ago













Against malicious input... theoretical API for settings validity of max 2 years accepts a Period. Malicious input is 0 years, 1 month, 3650 days. You normalize and check year <= 2 and months accordingly. Yet, you set 10 years and a 1 month. (I know, it's a stretch, but you get the idea.)

– D. Kovács
8 hours ago





Against malicious input... theoretical API for settings validity of max 2 years accepts a Period. Malicious input is 0 years, 1 month, 3650 days. You normalize and check year <= 2 and months accordingly. Yet, you set 10 years and a 1 month. (I know, it's a stretch, but you get the idea.)

– D. Kovács
8 hours ago




1




1





I would check the date I get as a result from using the period, not the period itself. But I guess it really depends on what the API is actually doing.

– Max Vollmer
7 hours ago






I would check the date I get as a result from using the period, not the period itself. But I guess it really depends on what the API is actually doing.

– Max Vollmer
7 hours ago







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f57021385%2fwhy-does-java-time-periodnormalized-not-normalize-days%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單