Why does java.time.Period#normalized() not normalize days?What is reflection and why is it useful?Does a...

A DVR algebra with weird automorphisms

What to put after taking off rear stabilisers from child bicyle?

How to check the quality of an audio sample?

When is pointing out a person's hypocrisy not considered to be a logical fallacy?

Why would an Inquisitive rogue choose to use Insightful Fighting as opposed to using their Cunning Action to Hide?

Why the term 'unified' in "unified mass unit"?

Why did the Japanese attack the Aleutians at the same time as Midway?

Was the Ford Model T black because of the speed black paint dries?

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

Did any of the founding fathers anticipate Lysander Spooner's criticism of the constitution?

Why did my rum cake turn black?

Players of unusual orchestral instruments

I quit, and boss offered me 3 month "grace period" where I could still come back

Why does Hellboy file down his horns?

Is it rude to tell recruiters I would only change jobs for a better salary?

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

Can anybody provide any information about this equation?

Is purchasing foreign currency before going abroad a losing proposition?

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

Why would guns not work in the dungeon?

Do native speakers use ZVE or CPU?

Mistakenly modified `/bin/sh'

Can I play a first turn Simic Growth Chamber to have 3 mana available in the second turn?

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



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
    8 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
    8 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 7 hours ago









Basil Bourque

127k36 gold badges427 silver badges600 bronze badges




127k36 gold badges427 silver badges600 bronze badges










asked 8 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
    8 hours ago



















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

    – D. Kovács
    8 hours ago

















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

– D. Kovács
8 hours ago





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

– D. Kovács
8 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
    7 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
    6 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
    7 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
    6 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
    7 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
    6 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 8 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
    7 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
    6 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
    7 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
    6 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
7 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
7 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
6 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
6 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

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...