-
Notifications
You must be signed in to change notification settings - Fork 180
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
Implement formatting for Chinese calendar with some todos #3760
Merged
Merged
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ba3d48c
Necessary additions of Chinese to AnyCalendar
atcupps 2afaf93
First phase of formatting for chinese calendar
atcupps 981a3b5
Add macros for chinese calendar fmt
atcupps 5f714a8
Add field support for U and r
atcupps 53995a2
Merge branch 'extra-year-fields' into chinese-fmt
atcupps 29a8c95
Complete formatting with some todos
atcupps 7030380
Add issues to todos
atcupps 5d1a32e
Cargo fmt
atcupps 4370a0e
Add files
atcupps 2b67c84
Merge branch 'main' into chinese-fmt
atcupps ec9517b
Merge branch 'main' into chinese-fmt
atcupps b971070
get_symbol_for_month -> get_symbols_for_month
Manishearth c61257a
Add `get_normal_if_leap` method on `MonthCode`
atcupps 1b5424d
Placeholder support for leap months
atcupps 27c7666
Address clippy
atcupps 0c5cae8
Address comments from @manishearth
atcupps fb2d2e0
Merge branch 'main' into chinese-fmt
atcupps e29f54c
Merge branch 'main' into chinese-fmt
atcupps File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ use core::convert::TryInto; | |
use core::fmt; | ||
use core::ops::{Add, AddAssign, Sub, SubAssign}; | ||
use core::str::FromStr; | ||
use tinystr::TinyAsciiStr; | ||
use tinystr::{TinyStr16, TinyStr4}; | ||
use zerovec::maps::ZeroMapKV; | ||
use zerovec::ule::AsULE; | ||
|
@@ -92,6 +93,35 @@ impl FormattableYear { | |
#[cfg_attr(feature = "serde", derive(serde::Deserialize))] | ||
pub struct MonthCode(pub TinyStr4); | ||
|
||
impl MonthCode { | ||
/// Returns an option which is Some containing the non-month version of a leap month | ||
/// if the MonthCode this method is called upon is a leap month, and None otherwise. | ||
/// This method assumes the MonthCode is valid. | ||
pub fn get_normal_if_leap(self) -> Option<MonthCode> { | ||
let bytes = self.0.all_bytes(); | ||
if bytes[3] == b'L' { | ||
Some(MonthCode(TinyAsciiStr::from_bytes(&bytes[0..3]).ok()?)) | ||
} else { | ||
None | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_get_normal_month_code_if_leap() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: thanks for writing a test! |
||
let mc1 = MonthCode(tinystr::tinystr!(4, "M01L")); | ||
let result1 = mc1.get_normal_if_leap(); | ||
assert_eq!(result1, Some(MonthCode(tinystr::tinystr!(4, "M01")))); | ||
|
||
let mc2 = MonthCode(tinystr::tinystr!(4, "M11L")); | ||
let result2 = mc2.get_normal_if_leap(); | ||
assert_eq!(result2, Some(MonthCode(tinystr::tinystr!(4, "M11")))); | ||
|
||
let mc_invalid = MonthCode(tinystr::tinystr!(4, "M10")); | ||
let result_invalid = mc_invalid.get_normal_if_leap(); | ||
assert_eq!(result_invalid, None); | ||
} | ||
|
||
impl AsULE for MonthCode { | ||
type ULE = TinyStr4; | ||
fn to_unaligned(self) -> TinyStr4 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: how does this code not create a
clippy::indexing_slicing
failure? Is Clippy smart enough to know that this is a[u8; 4]
and that the indices are in range?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes