Skip to content

8334742: Change java.time month/day field types to 'byte' #24975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/java.base/share/classes/java/time/LocalDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ public final class LocalDate
/**
* @serial The month-of-year.
*/
private final short month;
private final byte month;
/**
* @serial The day-of-month.
*/
private final short day;
private final byte day;

//-----------------------------------------------------------------------
/**
Expand Down Expand Up @@ -490,8 +490,8 @@ private static LocalDate resolvePreviousValid(int year, int month, int day) {
*/
private LocalDate(int year, int month, int dayOfMonth) {
this.year = year;
this.month = (short) month;
this.day = (short) dayOfMonth;
this.month = (byte) month;
this.day = (byte) dayOfMonth;
}

//-----------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions src/java.base/share/classes/java/time/MonthDay.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ public final class MonthDay
/**
* @serial The month-of-year, not null.
*/
private final int month;
private final byte month;
/**
* @serial The day-of-month.
*/
private final int day;
private final byte day;

//-----------------------------------------------------------------------
/**
Expand Down Expand Up @@ -319,8 +319,8 @@ public static MonthDay parse(CharSequence text, DateTimeFormatter formatter) {
* @param dayOfMonth the day-of-month to represent, validated from 1 to 29-31
*/
private MonthDay(int month, int dayOfMonth) {
this.month = month;
this.day = dayOfMonth;
this.month = (byte) month;
this.day = (byte) dayOfMonth;
}

//-----------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/time/YearMonth.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public final class YearMonth
/**
* @serial The month-of-year, not null.
*/
private final int month;
private final byte month;

//-----------------------------------------------------------------------
/**
Expand Down Expand Up @@ -306,7 +306,7 @@ public static YearMonth parse(CharSequence text, DateTimeFormatter formatter) {
*/
private YearMonth(int year, int month) {
this.year = year;
this.month = month;
this.month = (byte) month;
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/java.base/share/classes/java/time/chrono/HijrahDate.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -137,11 +137,11 @@ public final class HijrahDate
/**
* The month-of-year.
*/
private final transient int monthOfYear;
private final transient byte monthOfYear;
/**
* The day-of-month.
*/
private final transient int dayOfMonth;
private final transient byte dayOfMonth;

//-------------------------------------------------------------------------
/**
Expand Down Expand Up @@ -273,8 +273,8 @@ private HijrahDate(HijrahChronology chrono, int prolepticYear, int monthOfYear,

this.chrono = chrono;
this.prolepticYear = prolepticYear;
this.monthOfYear = monthOfYear;
this.dayOfMonth = dayOfMonth;
this.monthOfYear = (byte) monthOfYear;
this.dayOfMonth = (byte) dayOfMonth;
}

/**
Expand All @@ -287,8 +287,8 @@ private HijrahDate(HijrahChronology chrono, long epochDay) {

this.chrono = chrono;
this.prolepticYear = dateInfo[0];
this.monthOfYear = dateInfo[1];
this.dayOfMonth = dateInfo[2];
this.monthOfYear = (byte) dateInfo[1];
this.dayOfMonth = (byte) dateInfo[2];
}

//-----------------------------------------------------------------------
Expand Down