spreadsheet_ods/format/
builder.rs

1use crate::format::{
2    FormatCalendarStyle, FormatNumberStyle, FormatPart, FormatPartType, ValueFormatTrait,
3};
4use icu_locid::Locale;
5
6/// Builder for FormatPart with type Number.
7#[derive(Debug)]
8pub struct PartNumberBuilder<'vf, T: ValueFormatTrait> {
9    part: FormatPart,
10    valueformat: &'vf mut T,
11}
12
13impl<'vf, T: ValueFormatTrait> PartNumberBuilder<'vf, T> {
14    /// New builder for the valueformat.
15    pub fn new<'a>(valueformat: &'a mut T) -> Self
16    where
17        'a: 'vf,
18    {
19        Self {
20            part: FormatPart::new(FormatPartType::Number),
21            valueformat,
22        }
23    }
24
25    /// Appends the constructed FormatPart to the original value format.
26    pub fn build(self) {
27        self.valueformat.push_part(self.part);
28    }
29
30    /// Only applies the builder if the test is true.
31    #[must_use]
32    pub fn if_then<F>(self, test: bool, build: F) -> Self
33    where
34        F: Fn(Self) -> Self,
35    {
36        if test {
37            build(self)
38        } else {
39            self
40        }
41    }
42
43    /// If the number:decimal-places attribute is not specified, the number of decimal places
44    /// specified by the default table cell style is used.
45    #[must_use]
46    pub fn decimal_places(mut self, decimal_places: u8) -> Self {
47        self.part
48            .set_attr("number:decimal-places", decimal_places.to_string());
49        self
50    }
51
52    /// Sets decimal_places and min_decimal_places to the same value,
53    /// which in effect always displays the same number of decimals.
54    #[must_use]
55    pub fn fixed_decimal_places(mut self, decimal_places: u8) -> Self {
56        self.part
57            .set_attr("number:decimal-places", decimal_places.to_string());
58        self.part
59            .set_attr("number:min-decimal-places", decimal_places.to_string());
60        self
61    }
62
63    /// The number:grouping attribute specifies whether the integer digits of a number should be
64    /// grouped using a separator character.
65    /// The grouping character that is used and the number of digits that are grouped together depends
66    /// on the language and country of the style.
67    /// The defined values for the number:grouping attribute are:
68    /// * false: integer digits of a number are not grouped using a separator character.
69    /// * true: integer digits of a number should be grouped by a separator character.
70    /// The default value for this attribute is false.
71    #[must_use]
72    pub fn grouping(mut self) -> Self {
73        self.part.set_attr("number:grouping", String::from("true"));
74        self
75    }
76
77    /// The number:min-decimal-places attribute specifies the minimum number of digits in the
78    /// decimal part.
79    /// The value of the number:min-decimal-places attribute shall not be greater than the value of
80    /// the number:decimal-places 19.343 attribute.
81    /// If the value of number:min-decimal-places is less than the value of number:decimalplaces, trailing zero digits in decimal places following the position indicated by the value of
82    /// number:min-decimal-places shall not be displayed.
83    #[must_use]
84    pub fn min_decimal_places(mut self, min_decimal_places: u8) -> Self {
85        self.part
86            .set_attr("number:min-decimal-places", min_decimal_places.to_string());
87        self
88    }
89
90    /// The number:min-integer-digits attribute specifies the minimum number of integer digits to
91    /// display in the integer portion of a number, a scientific number, or a fraction.
92    /// For a number:fraction element, if the number:min-integer-digits attribute is not
93    /// present, no integer portion is displayed.
94    #[must_use]
95    pub fn min_integer_digits(mut self, mininteger_digits: u8) -> Self {
96        self.part
97            .set_attr("number:min-integer-digits", mininteger_digits.to_string());
98        self
99    }
100
101    /// The number:display-factor attribute specifies a factor by which each number is scaled
102    /// (divided) before displaying.
103    /// The default value for this attribute is 1
104    #[must_use]
105    pub fn display_factor(mut self, display_factor: f64) -> Self {
106        self.part
107            .set_attr("number:display-factor", display_factor.to_string());
108        self
109    }
110
111    /// The number:decimal-replacement attribute specifies a replacement text for decimal places if
112    /// a number style specifies that decimal places are used but the number displayed is an integer.
113    /// Note: What replacement text is supported is implementation-dependent
114    #[must_use]
115    pub fn decimal_replacement(mut self, decimal_replacement: char) -> Self {
116        self.part.set_attr(
117            "number:decimal-replacement",
118            decimal_replacement.to_string(),
119        );
120        self
121    }
122
123    /// The number:embedded-text element specifies text that is displayed at one specific position
124    /// within a number.
125
126    ///
127    /// The number:embedded-text element is usable within the following element:
128    /// * number:number 16.29.3.
129    ///
130    /// The number:embedded-text element has the following attribute:
131    /// * number:position 19.358.
132    ///
133    /// The number:position attribute specifies the position where text appears.
134    /// The index of a position starts with 1 and is counted by digits from right to left in the integer part of
135    /// a number, starting left from a decimal separator if one exists, or from the last digit of the number.
136    /// Text is inserted before the digit at the specified position. If the value of number:position
137    /// attribute is greater than the value of number:min-integer-digits 19.355 and greater than
138    /// the number of integer digits in the number, text is prepended to the number.    
139    ///
140    /// The number:embedded-text element has no child elements.
141    /// The number:embedded-text element has character data content
142    #[must_use]
143    pub fn embedded_text<S: Into<String>>(mut self, text: S, pos: i32) -> Self {
144        self.part.position = Some(pos);
145        self.part.content = Some(text.into());
146        self
147    }
148}
149
150/// Builder for FormatPart with type Number.
151#[derive(Debug)]
152pub struct PartFillCharacterBuilder<'vf, T: ValueFormatTrait> {
153    part: FormatPart,
154    valueformat: &'vf mut T,
155}
156
157impl<'vf, T: ValueFormatTrait> PartFillCharacterBuilder<'vf, T> {
158    /// New builder for the valueformat.
159    pub fn new<'a>(valueformat: &'a mut T) -> Self
160    where
161        'a: 'vf,
162    {
163        Self {
164            part: FormatPart::new(FormatPartType::FillCharacter),
165            valueformat,
166        }
167    }
168
169    /// Appends the constructed FormatPart to the original value format.
170    pub fn build(self) {
171        self.valueformat.push_part(self.part);
172    }
173
174    /// Only applies the builder if the test is true.
175    #[must_use]
176    pub fn if_then<F>(self, test: bool, build: F) -> Self
177    where
178        F: Fn(Self) -> Self,
179    {
180        if test {
181            build(self)
182        } else {
183            self
184        }
185    }
186
187    /// If the number:decimal-places attribute is not specified, the number of decimal places
188    /// specified by the default table cell style is used.
189    #[must_use]
190    pub fn fill_char(mut self, c: char) -> Self {
191        self.part.set_content(c.to_string());
192        self
193    }
194}
195
196/// Builder for FormatPart with type ScientificNumber.
197///
198/// The number:scientific-number element specifies the display formatting properties for a
199/// number style that should be displayed in scientific format.
200///
201/// The number:scientific-number element is usable within the following element:
202/// * number:number-style 16.27.2.
203///
204/// The number:scientific-number element has the following attributes:
205/// * number:decimal-places 19.343.4,
206/// * number:grouping 19.348,
207/// * number:min-exponentdigits 19.351 and
208/// * number:min-integer-digits 19.352.
209///
210/// The number:scientific-number element has no child elements.
211#[derive(Debug)]
212pub struct PartScientificBuilder<'vf, T: ValueFormatTrait> {
213    part: FormatPart,
214    valueformat: &'vf mut T,
215}
216
217impl<'vf, T: ValueFormatTrait> PartScientificBuilder<'vf, T> {
218    /// New builder for the valueformat.
219    pub fn new<'a>(valueformat: &'a mut T) -> Self
220    where
221        'a: 'vf,
222    {
223        Self {
224            part: FormatPart::new(FormatPartType::ScientificNumber),
225            valueformat,
226        }
227    }
228
229    /// Appends the constructed FormatPart to the original value format.
230    pub fn build(self) {
231        self.valueformat.push_part(self.part);
232    }
233
234    /// Only applies the builder if the test is true.
235    #[must_use]
236    pub fn if_then<F>(self, test: bool, build: F) -> Self
237    where
238        F: Fn(Self) -> Self,
239    {
240        if test {
241            build(self)
242        } else {
243            self
244        }
245    }
246
247    /// If the number:decimal-places attribute is not specified, the number of decimal places
248    /// specified by the default table cell style is used.
249    #[must_use]
250    pub fn decimal_places(mut self, v: u8) -> Self {
251        self.part.set_attr("number:decimal-places", v.to_string());
252        self
253    }
254
255    /// The number:exponent-interval attribute determines the valid exponents to be used: the
256    /// valid exponents are the integer multiples of the value of the number:exponent-interval
257    /// attribute.
258    /// The default value for this attribute is 1.
259    #[must_use]
260    pub fn expontent_interval(mut self, v: u8) -> Self {
261        self.part
262            .set_attr("number:exponent-interval", v.to_string());
263        self
264    }
265
266    /// The number:forced-exponent-sign attribute specifies whether the sign of the exponent for a
267    /// scientific number is always displayed.
268    /// The defined values for the number:forced-exponent-sign attribute are:
269    /// * false: the exponent sign is displayed only for a negative value of the exponent, otherwise it
270    /// is not displayed.
271    /// * true: the exponent sign is always displayed regardless of the value of exponent.
272    /// The default value for this attribute is true.
273    #[must_use]
274    pub fn forced_exponent_sign(mut self, v: bool) -> Self {
275        self.part
276            .set_attr("number:forced-exponent-sign", v.to_string());
277        self
278    }
279
280    /// The number:grouping attribute specifies whether the integer digits of a number should be
281    /// grouped using a separator character.
282    /// The grouping character that is used and the number of digits that are grouped together depends
283    /// on the language and country of the style.
284    /// The defined values for the number:grouping attribute are:
285    /// * false: integer digits of a number are not grouped using a separator character.
286    /// * true: integer digits of a number should be grouped by a separator character.
287    /// The default value for this attribute is false.
288    #[must_use]
289    pub fn grouping(mut self) -> Self {
290        self.part.set_attr("number:grouping", String::from("true"));
291        self
292    }
293
294    /// The number:min-decimal-places attribute specifies the minimum number of digits in the
295    /// decimal part.
296    /// The value of the number:min-decimal-places attribute shall not be greater than the value of
297    /// the number:decimal-places 19.343 attribute.
298    /// If the value of number:min-decimal-places is less than the value of number:decimalplaces, trailing zero digits in decimal places following the position indicated by the value of
299    /// number:min-decimal-places shall not be displayed.
300    #[must_use]
301    pub fn min_decimal_places(mut self, v: u8) -> Self {
302        self.part
303            .set_attr("number:min-decimal-places", v.to_string());
304        self
305    }
306
307    /// The number:min-exponent-digits attribute specifies the minimum number of digits to use to
308    /// display an exponent.
309    #[must_use]
310    pub fn min_exponent_digits(mut self, v: u8) -> Self {
311        self.part
312            .set_attr("number:min-exponent-digits", v.to_string());
313        self
314    }
315
316    /// The number:min-integer-digits attribute specifies the minimum number of integer digits to
317    /// display in the integer portion of a number, a scientific number, or a fraction.
318    /// For a number:fraction element, if the number:min-integer-digits attribute is not
319    /// present, no integer portion is displayed.
320    #[must_use]
321    pub fn min_integer_digits(mut self, v: u8) -> Self {
322        self.part
323            .set_attr("number:min-integer-digits", v.to_string());
324        self
325    }
326}
327
328/// The number:fraction element specifies the display formatting properties for a number style
329/// that should be displayed as a fraction.
330///
331/// The number:fraction element is usable within the following element:
332/// * number:numberstyle 16.29.2.
333///
334/// The number:fraction element has the following attributes:
335/// * number:denominatorvalue 19.345,
336/// * number:grouping 19.350,
337/// * number:max-denominator-value 19.352,
338/// * number:min-denominator-digits 19.353,
339/// * number:min-integer-digits 19.355 and
340/// * number:min-numerator-digits 19.357.
341///
342/// The number:fraction element has no child elements.
343#[derive(Debug)]
344pub struct PartFractionBuilder<'vf, T: ValueFormatTrait> {
345    part: FormatPart,
346    valueformat: &'vf mut T,
347}
348
349impl<'vf, T: ValueFormatTrait> PartFractionBuilder<'vf, T> {
350    /// New builder for the valueformat.
351    pub fn new<'a>(valueformat: &'a mut T) -> Self
352    where
353        'a: 'vf,
354    {
355        Self {
356            part: FormatPart::new(FormatPartType::Fraction),
357            valueformat,
358        }
359    }
360
361    /// Appends the constructed FormatPart to the original value format.
362    pub fn build(self) {
363        self.valueformat.push_part(self.part);
364    }
365
366    /// Only applies the builder if the test is true.
367    #[must_use]
368    pub fn if_then<F>(self, test: bool, build: F) -> Self
369    where
370        F: Fn(Self) -> Self,
371    {
372        if test {
373            build(self)
374        } else {
375            self
376        }
377    }
378
379    /// The number:denominator-value attribute specifies an integer value that is used as the
380    /// denominator of a fraction. If this attribute is not present, a denominator that is appropriate for
381    /// displaying the number is used.
382    #[must_use]
383    pub fn denominator(mut self, v: i64) -> Self {
384        self.part
385            .set_attr("number:denominator-value", v.to_string());
386        self
387    }
388
389    /// The number:grouping attribute specifies whether the integer digits of a number should be
390    /// grouped using a separator character.
391    /// The grouping character that is used and the number of digits that are grouped together depends
392    /// on the language and country of the style.
393    /// The defined values for the number:grouping attribute are:
394    /// * false: integer digits of a number are not grouped using a separator character.
395    /// * true: integer digits of a number should be grouped by a separator character.
396    /// The default value for this attribute is false.
397    #[must_use]
398    pub fn grouping(mut self) -> Self {
399        self.part.set_attr("number:grouping", String::from("true"));
400        self
401    }
402
403    /// The number:max-denominator-value attribute specifies the maximum
404    /// denominator permitted to be chosen if its number:fraction element does not
405    /// have a number:denominator-value attribute. The number:max-denominator-value
406    /// attribute is ignored in the presence of a number:denominator-value 19.345
407    /// attribute. The absence of the number:max-denominator-value attribute indicates
408    /// that no maximum denominator is specified.
409    #[must_use]
410    pub fn max_denominator(mut self, v: i64) -> Self {
411        self.part
412            .set_attr("number:max-denominator-value", v.to_string());
413        self
414    }
415
416    /// The number:min-denominator-digits attribute specifies the minimum number of digits to
417    /// use to display the denominator of a fraction.
418    #[must_use]
419    pub fn min_denominator_digits(mut self, v: u8) -> Self {
420        self.part
421            .set_attr("number:min-denominator-digits", v.to_string());
422        self
423    }
424
425    /// The number:min-integer-digits attribute specifies the minimum number of integer digits to
426    /// display in the integer portion of a number, a scientific number, or a fraction.
427    /// For a number:fraction element, if the number:min-integer-digits attribute is not
428    /// present, no integer portion is displayed.
429    #[must_use]
430    pub fn min_integer_digits(mut self, v: u8) -> Self {
431        self.part
432            .set_attr("number:min-numerator-digits", v.to_string());
433        self
434    }
435
436    /// The number:min-numerator-digits attribute specifies the minimum number of digits to use
437    /// to display the numerator in a fraction.
438    #[must_use]
439    pub fn min_numerator_digits(mut self, v: u8) -> Self {
440        self.part
441            .set_attr("number:min-numerator-digits", v.to_string());
442        self
443    }
444}
445
446/// The number:currency-symbol element specifies whether a currency symbol is displayed in
447/// a currency style.
448/// The content of this element is the text that is displayed as the currency symbol.
449/// If the element is empty or contains white space characters only, the default currency
450/// symbol for the currency style or the language and country of the currency style is displayed.
451///
452/// The number:currency-symbol element is usable within the following element:
453/// * number:currency-style 16.27.7.
454///
455/// The number:currency-symbol element has the following attributes:
456/// * number:country 19.342,
457/// * number:language 19.349,
458/// * number:rfc-language-tag 19.356 and
459/// * number:script 19.357.
460///
461/// The number:currency-symbol element has no child elements.
462/// The number:currency-symbol element has character data content.
463#[derive(Debug)]
464pub struct PartCurrencySymbolBuilder<'vf, T: ValueFormatTrait> {
465    part: FormatPart,
466    valueformat: &'vf mut T,
467}
468
469impl<'vf, T: ValueFormatTrait> PartCurrencySymbolBuilder<'vf, T> {
470    /// New builder for the valueformat.
471    pub fn new<'a>(valueformat: &'a mut T) -> Self
472    where
473        'a: 'vf,
474    {
475        Self {
476            part: FormatPart::new(FormatPartType::CurrencySymbol),
477            valueformat,
478        }
479    }
480
481    /// Appends the constructed FormatPart to the original value format.
482    pub fn build(self) {
483        self.valueformat.push_part(self.part);
484    }
485
486    /// Only applies the builder if the test is true.
487    #[must_use]
488    pub fn if_then<F>(self, test: bool, build: F) -> Self
489    where
490        F: Fn(Self) -> Self,
491    {
492        if test {
493            build(self)
494        } else {
495            self
496        }
497    }
498
499    /// The number:language attribute specifies a language code. The country code is used for
500    /// formatting properties whose evaluation is locale-dependent.
501    /// If a language code is not specified, either the system settings or the setting for the system's
502    /// language are used, depending on the property whose value should be evaluated.
503    ///
504    /// The number:country attribute specifies a country code for a data style. The country code is
505    /// used for formatting properties whose evaluation is locale-dependent.
506    /// If a country is not specified, the system settings are used.
507    /// The number:country attribute on a number:currency-symbol element, specifies the
508    /// country of a currency symbol.
509    ///
510    /// The number:script attribute specifies a script code. The script code is used for formatting
511    /// properties whose evaluation is locale-dependent. The attribute should be used only if necessary
512    /// according to the rules of §2.2.3 of [RFC5646](https://datatracker.ietf.org/doc/html/rfc5646), or its successors.
513    #[must_use]
514    pub fn locale(mut self, v: Locale) -> Self {
515        self.part
516            .set_attr("number:language", v.id.language.to_string());
517        if let Some(region) = v.id.region {
518            self.part.set_attr("number:country", region.to_string());
519        }
520        if let Some(script) = v.id.script {
521            self.part.set_attr("number:script", script.to_string());
522        }
523        self
524    }
525
526    /// Symbol text that is used for the currency symbol. If not set
527    /// the default according to the country is used.
528    #[must_use]
529    pub fn symbol<S: Into<String>>(mut self, v: S) -> Self {
530        self.part.set_content(v.into());
531        self
532    }
533}
534
535/// The number:day element specifies a day of a month in a date.
536///
537/// The number:day element is usable within the following element:
538/// * number:date-style 16.27.10.
539///
540/// The number:day element has the following attributes:
541/// * number:calendar 19.341 and
542/// * number:style 19.358.2.
543///
544/// The number:day element has no child elements.
545#[derive(Debug)]
546pub struct PartDayBuilder<'vf, T: ValueFormatTrait> {
547    part: FormatPart,
548    valueformat: &'vf mut T,
549}
550
551impl<'vf, T: ValueFormatTrait> PartDayBuilder<'vf, T> {
552    /// New builder for the valueformat.
553    pub fn new<'a>(valueformat: &'a mut T) -> Self
554    where
555        'a: 'vf,
556    {
557        Self {
558            part: FormatPart::new(FormatPartType::Day),
559            valueformat,
560        }
561    }
562
563    /// Appends the constructed FormatPart to the original value format.
564    pub fn build(self) {
565        self.valueformat.push_part(self.part);
566    }
567
568    /// Only applies the builder if the test is true.
569    #[must_use]
570    pub fn if_then<F>(self, test: bool, build: F) -> Self
571    where
572        F: Fn(Self) -> Self,
573    {
574        if test {
575            build(self)
576        } else {
577            self
578        }
579    }
580
581    /// The number:style attribute specifies whether the content of a time element is displayed in short
582    /// or long format. The value of this attribute can be short or long. The meaning of these values
583    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
584    /// or time style.
585    #[must_use]
586    pub fn long_style(mut self) -> Self {
587        self.part.set_attr("number:style", "long".to_string());
588        self
589    }
590
591    /// The number:style attribute specifies whether the content of a time element is displayed in short
592    /// or long format. The value of this attribute can be short or long. The meaning of these values
593    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
594    /// or time style.
595    #[must_use]
596    pub fn short_style(mut self) -> Self {
597        self.part.set_attr("number:style", "short".to_string());
598        self
599    }
600
601    /// The number:style attribute specifies whether the content of a time element is displayed in short
602    /// or long format. The value of this attribute can be short or long. The meaning of these values
603    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
604    /// or time style.
605    #[must_use]
606    pub fn style(mut self, style: FormatNumberStyle) -> Self {
607        self.part.set_attr("number:style", style.to_string());
608        self
609    }
610
611    /// The number:calendar attribute specifies the calendar system used to extract parts of a date.
612    ///
613    /// The attribute value may also be a string value. If this attribute is not specified, the default calendar
614    /// system for the locale of the data style is used.
615    #[must_use]
616    pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
617        self.part.set_attr("number:calendar", calendar.to_string());
618        self
619    }
620}
621
622/// Builder for FormatPart with type Month.
623///
624/// The number:month element specifies a month in a date.
625///
626/// The number:month element is usable within the following element:
627/// * number:date-style 16.27.10.
628///
629/// The number:month element has the following attributes:
630/// number:calendar 19.341,
631/// number:possessive-form 19.355,
632/// number:style 19.358.7 and
633/// number:textual 19.359.
634///
635/// The number:month element has no child elements
636#[derive(Debug)]
637pub struct PartMonthBuilder<'vf, T: ValueFormatTrait> {
638    part: FormatPart,
639    valueformat: &'vf mut T,
640}
641
642impl<'vf, T: ValueFormatTrait> PartMonthBuilder<'vf, T> {
643    /// New builder for the valueformat.
644    pub fn new<'a>(valueformat: &'a mut T) -> Self
645    where
646        'a: 'vf,
647    {
648        Self {
649            part: FormatPart::new(FormatPartType::Month),
650            valueformat,
651        }
652    }
653
654    /// Appends the constructed FormatPart to the original value format.
655    pub fn build(self) {
656        self.valueformat.push_part(self.part);
657    }
658
659    /// Only applies the builder if the test is true.
660    #[must_use]
661    pub fn if_then<F>(self, test: bool, build: F) -> Self
662    where
663        F: Fn(Self) -> Self,
664    {
665        if test {
666            build(self)
667        } else {
668            self
669        }
670    }
671
672    /// The number:style attribute specifies whether the content of a time element is displayed in short
673    /// or long format. The value of this attribute can be short or long. The meaning of these values
674    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
675    /// or time style.
676    #[must_use]
677    pub fn long_style(mut self) -> Self {
678        self.part.set_attr("number:style", "long".to_string());
679        self
680    }
681
682    /// The number:style attribute specifies whether the content of a time element is displayed in short
683    /// or long format. The value of this attribute can be short or long. The meaning of these values
684    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
685    /// or time style.
686    #[must_use]
687    pub fn short_style(mut self) -> Self {
688        self.part.set_attr("number:style", "short".to_string());
689        self
690    }
691
692    /// The number:style attribute specifies whether the content of a time element is displayed in short
693    /// or long format. The value of this attribute can be short or long. The meaning of these values
694    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
695    /// or time style.
696    #[must_use]
697    pub fn style(mut self, style: FormatNumberStyle) -> Self {
698        self.part.set_attr("number:style", style.to_string());
699        self
700    }
701
702    /// The number:textual attribute specifies whether the name or number of a month is displayed in
703    /// the month portion of a date.
704    /// The defined values for the number:textual element are:
705    /// * false: the number of the month is displayed.
706    /// * true: the name of the month is displayed.
707    /// The name or number of a month is defined by the number:calendar 19.341 attribute on the
708    /// same parent element as the number:textual attribute.
709    /// The default value for this attribute is false.
710    #[must_use]
711    pub fn textual(mut self) -> Self {
712        self.part.set_attr("number:textual", true.to_string());
713        self
714    }
715
716    /// The number:possessive-form attribute specifies whether the month is displayed as a noun or
717    /// using the possessive form.
718    /// The number:possessive-form attribute is only applied when a number:textual 19.363
719    /// attribute on the same number:month element has the value of true.
720    /// The defined values for the number:possessive-form attribute are:
721    /// * false: the name of the month is displayed in nominative form.
722    /// * true: the name of the month is displayed in possessive form.
723    #[must_use]
724    pub fn possessive_form(mut self) -> Self {
725        self.part
726            .set_attr("number:possessive-form", true.to_string());
727        self
728    }
729
730    /// The number:calendar attribute specifies the calendar system used to extract parts of a date.
731    ///
732    /// The attribute value may also be a string value. If this attribute is not specified, the default calendar
733    /// system for the locale of the data style is used.
734    #[must_use]
735    pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
736        self.part.set_attr("number:calendar", calendar.to_string());
737        self
738    }
739}
740
741/// The number:year element specifies a year in a date.
742/// The number:year element is usable within the following element:
743/// * number:date-style 16.27.10.
744///
745/// The number:year element has the following attributes:
746/// * number:calendar 19.341 and
747/// * number:style 19.358.10.
748///
749/// The number:year element has no child elements.
750#[derive(Debug)]
751pub struct PartYearBuilder<'vf, T: ValueFormatTrait> {
752    part: FormatPart,
753    valueformat: &'vf mut T,
754}
755
756impl<'vf, T: ValueFormatTrait> PartYearBuilder<'vf, T> {
757    /// New builder for the valueformat.
758    pub fn new<'a>(valueformat: &'a mut T) -> Self
759    where
760        'a: 'vf,
761    {
762        Self {
763            part: FormatPart::new(FormatPartType::Year),
764            valueformat,
765        }
766    }
767
768    /// Appends the constructed FormatPart to the original value format.
769    pub fn build(self) {
770        self.valueformat.push_part(self.part);
771    }
772
773    /// Only applies the builder if the test is true.
774    #[must_use]
775    pub fn if_then<F>(self, test: bool, build: F) -> Self
776    where
777        F: Fn(Self) -> Self,
778    {
779        if test {
780            build(self)
781        } else {
782            self
783        }
784    }
785
786    /// The number:style attribute specifies whether the content of a time element is displayed in short
787    /// or long format. The value of this attribute can be short or long. The meaning of these values
788    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
789    /// or time style.
790    #[must_use]
791    pub fn long_style(mut self) -> Self {
792        self.part.set_attr("number:style", "long".to_string());
793        self
794    }
795
796    /// The number:style attribute specifies whether the content of a time element is displayed in short
797    /// or long format. The value of this attribute can be short or long. The meaning of these values
798    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
799    /// or time style.
800    #[must_use]
801    pub fn short_style(mut self) -> Self {
802        self.part.set_attr("number:style", "short".to_string());
803        self
804    }
805
806    /// The number:style attribute specifies whether the content of a time element is displayed in short
807    /// or long format. The value of this attribute can be short or long. The meaning of these values
808    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
809    /// or time style.
810    #[must_use]
811    pub fn style(mut self, style: FormatNumberStyle) -> Self {
812        self.part.set_attr("number:style", style.to_string());
813        self
814    }
815
816    /// The number:calendar attribute specifies the calendar system used to extract parts of a date.
817    ///
818    /// The attribute value may also be a string value. If this attribute is not specified, the default calendar
819    /// system for the locale of the data style is used.
820    #[must_use]
821    pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
822        self.part.set_attr("number:calendar", calendar.to_string());
823        self
824    }
825}
826
827/// The number:era element specifies an era in which a year is counted.
828///
829/// The number:era element is usable within the following element:
830/// * number:date-style 16.27.10.
831///
832/// The number:era element has the following attributes:
833/// * number:calendar 19.341 and
834/// * number:style 19.358.4.
835///
836/// The number:era element has no child elements
837#[derive(Debug)]
838pub struct PartEraBuilder<'vf, T: ValueFormatTrait> {
839    part: FormatPart,
840    valueformat: &'vf mut T,
841}
842
843impl<'vf, T: ValueFormatTrait> PartEraBuilder<'vf, T> {
844    /// New builder for the valueformat.
845    pub fn new<'a>(valueformat: &'a mut T) -> Self
846    where
847        'a: 'vf,
848    {
849        Self {
850            part: FormatPart::new(FormatPartType::Era),
851            valueformat,
852        }
853    }
854
855    /// Appends the constructed FormatPart to the original value format.
856    pub fn build(self) {
857        self.valueformat.push_part(self.part);
858    }
859
860    /// Only applies the builder if the test is true.
861    #[must_use]
862    pub fn if_then<F>(self, test: bool, build: F) -> Self
863    where
864        F: Fn(Self) -> Self,
865    {
866        if test {
867            build(self)
868        } else {
869            self
870        }
871    }
872
873    /// The number:style attribute specifies whether the content of a time element is displayed in short
874    /// or long format. The value of this attribute can be short or long. The meaning of these values
875    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
876    /// or time style.
877    #[must_use]
878    pub fn long_style(mut self) -> Self {
879        self.part.set_attr("number:style", "long".to_string());
880        self
881    }
882
883    /// The number:style attribute specifies whether the content of a time element is displayed in short
884    /// or long format. The value of this attribute can be short or long. The meaning of these values
885    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
886    /// or time style.
887    #[must_use]
888    pub fn short_style(mut self) -> Self {
889        self.part.set_attr("number:style", "short".to_string());
890        self
891    }
892
893    /// The number:style attribute specifies whether the content of a time element is displayed in short
894    /// or long format. The value of this attribute can be short or long. The meaning of these values
895    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
896    /// or time style.
897    #[must_use]
898    pub fn style(mut self, style: FormatNumberStyle) -> Self {
899        self.part.set_attr("number:style", style.to_string());
900        self
901    }
902
903    /// The number:calendar attribute specifies the calendar system used to extract parts of a date.
904    ///
905    /// The attribute value may also be a string value. If this attribute is not specified, the default calendar
906    /// system for the locale of the data style is used.
907    #[must_use]
908    pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
909        self.part.set_attr("number:calendar", calendar.to_string());
910        self
911    }
912}
913
914/// The number:day-of-week element specifies a day of a week in a date.
915///
916/// The number:day-of-week element is usable within the following element:
917/// * number:datestyle 16.27.10.
918///
919/// The number:day-of-week element has the following attributes:
920/// * number:calendar 19.341 and
921/// * number:style 19.358.3.
922///
923/// The number:day-of-week element has no child elements.
924#[derive(Debug)]
925pub struct PartDayOfWeekBuilder<'vf, T: ValueFormatTrait> {
926    part: FormatPart,
927    valueformat: &'vf mut T,
928}
929
930impl<'vf, T: ValueFormatTrait> PartDayOfWeekBuilder<'vf, T> {
931    /// New builder for the valueformat.
932    pub fn new<'a>(valueformat: &'a mut T) -> Self
933    where
934        'a: 'vf,
935    {
936        Self {
937            part: FormatPart::new(FormatPartType::DayOfWeek),
938            valueformat,
939        }
940    }
941
942    /// Appends the constructed FormatPart to the original value format.
943    pub fn build(self) {
944        self.valueformat.push_part(self.part);
945    }
946
947    /// Only applies the builder if the test is true.
948    #[must_use]
949    pub fn if_then<F>(self, test: bool, build: F) -> Self
950    where
951        F: Fn(Self) -> Self,
952    {
953        if test {
954            build(self)
955        } else {
956            self
957        }
958    }
959
960    /// The number:style attribute specifies whether the content of a time element is displayed in short
961    /// or long format. The value of this attribute can be short or long. The meaning of these values
962    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
963    /// or time style.
964    #[must_use]
965    pub fn long_style(mut self) -> Self {
966        self.part.set_attr("number:style", "long".to_string());
967        self
968    }
969
970    /// The number:style attribute specifies whether the content of a time element is displayed in short
971    /// or long format. The value of this attribute can be short or long. The meaning of these values
972    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
973    /// or time style.
974    #[must_use]
975    pub fn short_style(mut self) -> Self {
976        self.part.set_attr("number:style", "short".to_string());
977        self
978    }
979
980    /// The number:style attribute specifies whether the content of a time element is displayed in short
981    /// or long format. The value of this attribute can be short or long. The meaning of these values
982    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
983    /// or time style.
984    #[must_use]
985    pub fn style(mut self, style: FormatNumberStyle) -> Self {
986        self.part.set_attr("number:style", style.to_string());
987        self
988    }
989
990    /// The number:calendar attribute specifies the calendar system used to extract parts of a date.
991    ///
992    /// The attribute value may also be a string value. If this attribute is not specified, the default calendar
993    /// system for the locale of the data style is used.
994    #[must_use]
995    pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
996        self.part.set_attr("number:calendar", calendar.to_string());
997        self
998    }
999}
1000
1001/// The number:week-of-year element specifies a week of a year in a date.
1002///
1003/// The number:week-of-year element is usable within the following element:
1004/// * number:date-style 16.27.10.
1005///
1006/// The number:week-of-year element has the following attribute:
1007/// * number:calendar 19.341.
1008///
1009/// The number:week-of-year element has no child elements.
1010#[derive(Debug)]
1011pub struct PartWeekOfYearBuilder<'vf, T: ValueFormatTrait> {
1012    part: FormatPart,
1013    valueformat: &'vf mut T,
1014}
1015
1016impl<'vf, T: ValueFormatTrait> PartWeekOfYearBuilder<'vf, T> {
1017    /// New builder for the valueformat.
1018    pub fn new<'a>(valueformat: &'a mut T) -> Self
1019    where
1020        'a: 'vf,
1021    {
1022        Self {
1023            part: FormatPart::new(FormatPartType::WeekOfYear),
1024            valueformat,
1025        }
1026    }
1027
1028    /// Appends the constructed FormatPart to the original value format.
1029    pub fn build(self) {
1030        self.valueformat.push_part(self.part);
1031    }
1032
1033    /// Only applies the builder if the test is true.
1034    #[must_use]
1035    pub fn if_then<F>(self, test: bool, build: F) -> Self
1036    where
1037        F: Fn(Self) -> Self,
1038    {
1039        if test {
1040            build(self)
1041        } else {
1042            self
1043        }
1044    }
1045
1046    /// The number:calendar attribute specifies the calendar system used to extract parts of a date.
1047    ///
1048    /// The attribute value may also be a string value. If this attribute is not specified, the default calendar
1049    /// system for the locale of the data style is used.
1050    #[must_use]
1051    pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
1052        self.part.set_attr("number:calendar", calendar.to_string());
1053        self
1054    }
1055}
1056
1057/// The number:quarter element specifies a quarter of the year in a date.
1058///
1059/// The number:quarter element is usable within the following element:
1060/// * number:datestyle 16.27.10.
1061///
1062/// The number:quarter element has the following attributes:
1063/// * number:calendar 19.341 and
1064/// * number:style 19.358.8.
1065///
1066/// The number:quarter element has no child elements
1067#[derive(Debug)]
1068pub struct PartQuarterBuilder<'vf, T: ValueFormatTrait> {
1069    part: FormatPart,
1070    valueformat: &'vf mut T,
1071}
1072
1073impl<'vf, T: ValueFormatTrait> PartQuarterBuilder<'vf, T> {
1074    /// New builder for the valueformat.
1075    pub fn new<'a>(valueformat: &'a mut T) -> Self
1076    where
1077        'a: 'vf,
1078    {
1079        Self {
1080            part: FormatPart::new(FormatPartType::Quarter),
1081            valueformat,
1082        }
1083    }
1084
1085    /// Appends the constructed FormatPart to the original value format.
1086    pub fn build(self) {
1087        self.valueformat.push_part(self.part);
1088    }
1089
1090    /// Only applies the builder if the test is true.
1091    #[must_use]
1092    pub fn if_then<F>(self, test: bool, build: F) -> Self
1093    where
1094        F: Fn(Self) -> Self,
1095    {
1096        if test {
1097            build(self)
1098        } else {
1099            self
1100        }
1101    }
1102
1103    /// The number:style attribute specifies whether the content of a time element is displayed in short
1104    /// or long format. The value of this attribute can be short or long. The meaning of these values
1105    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1106    /// or time style.
1107    #[must_use]
1108    pub fn long_style(mut self) -> Self {
1109        self.part.set_attr("number:style", "long".to_string());
1110        self
1111    }
1112
1113    /// The number:style attribute specifies whether the content of a time element is displayed in short
1114    /// or long format. The value of this attribute can be short or long. The meaning of these values
1115    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1116    /// or time style.
1117    #[must_use]
1118    pub fn short_style(mut self) -> Self {
1119        self.part.set_attr("number:style", "short".to_string());
1120        self
1121    }
1122
1123    /// The number:style attribute specifies whether the content of a time element is displayed in short
1124    /// or long format. The value of this attribute can be short or long. The meaning of these values
1125    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1126    /// or time style.
1127    #[must_use]
1128    pub fn style(mut self, style: FormatNumberStyle) -> Self {
1129        self.part.set_attr("number:style", style.to_string());
1130        self
1131    }
1132
1133    /// The number:calendar attribute specifies the calendar system used to extract parts of a date.
1134    ///
1135    /// The attribute value may also be a string value. If this attribute is not specified, the default calendar
1136    /// system for the locale of the data style is used.
1137    #[must_use]
1138    pub fn calendar(mut self, calendar: FormatCalendarStyle) -> Self {
1139        self.part.set_attr("number:calendar", calendar.to_string());
1140        self
1141    }
1142}
1143
1144/// The number:hours element specifies whether hours are displayed as part of a date or time.
1145///
1146/// The number:hours element is usable within the following elements:
1147/// * number:datestyle 16.27.10 and
1148/// * number:time-style 16.27.18.
1149///
1150/// The number:hours element has the following attribute:
1151/// * number:style 19.358.5.
1152///
1153/// The number:hours element has no child elements.
1154#[derive(Debug)]
1155pub struct PartHoursBuilder<'vf, T: ValueFormatTrait> {
1156    part: FormatPart,
1157    valueformat: &'vf mut T,
1158}
1159
1160impl<'vf, T: ValueFormatTrait> PartHoursBuilder<'vf, T> {
1161    /// New builder for the valueformat.
1162    pub fn new<'a>(valueformat: &'a mut T) -> Self
1163    where
1164        'a: 'vf,
1165    {
1166        Self {
1167            part: FormatPart::new(FormatPartType::Hours),
1168            valueformat,
1169        }
1170    }
1171
1172    /// Appends the constructed FormatPart to the original value format.
1173    pub fn build(self) {
1174        self.valueformat.push_part(self.part);
1175    }
1176
1177    /// Only applies the builder if the test is true.
1178    #[must_use]
1179    pub fn if_then<F>(self, test: bool, build: F) -> Self
1180    where
1181        F: Fn(Self) -> Self,
1182    {
1183        if test {
1184            build(self)
1185        } else {
1186            self
1187        }
1188    }
1189
1190    /// The number:style attribute specifies whether the content of a time element is displayed in short
1191    /// or long format. The value of this attribute can be short or long. The meaning of these values
1192    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1193    /// or time style.
1194    #[must_use]
1195    pub fn long_style(mut self) -> Self {
1196        self.part.set_attr("number:style", "long".to_string());
1197        self
1198    }
1199
1200    /// The number:style attribute specifies whether the content of a time element is displayed in short
1201    /// or long format. The value of this attribute can be short or long. The meaning of these values
1202    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1203    /// or time style.
1204    #[must_use]
1205    pub fn short_style(mut self) -> Self {
1206        self.part.set_attr("number:style", "short".to_string());
1207        self
1208    }
1209
1210    /// The number:style attribute specifies whether the content of a time element is displayed in short
1211    /// or long format. The value of this attribute can be short or long. The meaning of these values
1212    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1213    /// or time style.
1214    #[must_use]
1215    pub fn style(mut self, style: FormatNumberStyle) -> Self {
1216        self.part.set_attr("number:style", style.to_string());
1217        self
1218    }
1219}
1220
1221/// The number:minutes element specifies whether minutes are displayed as part of a date or
1222/// time.
1223/// The number:minutes element is usable within the following elements:
1224/// * number:datestyle 16.27.10 and
1225/// * number:time-style 16.27.18.
1226///
1227/// The number:minutes element has the following attribute:
1228/// * number:style 19.358.6.
1229///
1230/// The number:minutes element has no child elements.
1231#[derive(Debug)]
1232pub struct PartMinutesBuilder<'vf, T: ValueFormatTrait> {
1233    part: FormatPart,
1234    valueformat: &'vf mut T,
1235}
1236
1237impl<'vf, T: ValueFormatTrait> PartMinutesBuilder<'vf, T> {
1238    /// New builder for the valueformat.
1239    pub fn new<'a>(valueformat: &'a mut T) -> Self
1240    where
1241        'a: 'vf,
1242    {
1243        Self {
1244            part: FormatPart::new(FormatPartType::Minutes),
1245            valueformat,
1246        }
1247    }
1248
1249    /// Appends the constructed FormatPart to the original value format.
1250    pub fn build(self) {
1251        self.valueformat.push_part(self.part);
1252    }
1253
1254    /// Only applies the builder if the test is true.
1255    #[must_use]
1256    pub fn if_then<F>(self, test: bool, build: F) -> Self
1257    where
1258        F: Fn(Self) -> Self,
1259    {
1260        if test {
1261            build(self)
1262        } else {
1263            self
1264        }
1265    }
1266
1267    /// The number:style attribute specifies whether the content of a time element is displayed in short
1268    /// or long format. The value of this attribute can be short or long. The meaning of these values
1269    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1270    /// or time style.
1271    #[must_use]
1272    pub fn long_style(mut self) -> Self {
1273        self.part.set_attr("number:style", "long".to_string());
1274        self
1275    }
1276
1277    /// The number:style attribute specifies whether the content of a time element is displayed in short
1278    /// or long format. The value of this attribute can be short or long. The meaning of these values
1279    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1280    /// or time style.
1281    #[must_use]
1282    pub fn short_style(mut self) -> Self {
1283        self.part.set_attr("number:style", "short".to_string());
1284        self
1285    }
1286
1287    /// The number:style attribute specifies whether the content of a time element is displayed in short
1288    /// or long format. The value of this attribute can be short or long. The meaning of these values
1289    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1290    /// or time style.
1291    #[must_use]
1292    pub fn style(mut self, style: FormatNumberStyle) -> Self {
1293        self.part.set_attr("number:style", style.to_string());
1294        self
1295    }
1296}
1297
1298/// The number:seconds element specifies whether seconds are displayed as part of a date or
1299/// time.
1300///
1301/// The number:seconds element is usable within the following elements:
1302/// * number:datestyle 16.27.10 and
1303/// * number:time-style 16.27.18.
1304///
1305/// The number:seconds element has the following attributes:
1306/// * number:decimal-places 19.343.3 and
1307/// * number:style 19.358.9.
1308///
1309/// The number:seconds element has no child elements.
1310#[derive(Debug)]
1311pub struct PartSecondsBuilder<'vf, T: ValueFormatTrait> {
1312    part: FormatPart,
1313    valueformat: &'vf mut T,
1314}
1315
1316impl<'vf, T: ValueFormatTrait> PartSecondsBuilder<'vf, T> {
1317    /// New builder for the valueformat.
1318    pub fn new<'a>(valueformat: &'a mut T) -> Self
1319    where
1320        'a: 'vf,
1321    {
1322        Self {
1323            part: FormatPart::new(FormatPartType::Seconds),
1324            valueformat,
1325        }
1326    }
1327
1328    /// Appends the constructed FormatPart to the original value format.
1329    pub fn build(self) {
1330        self.valueformat.push_part(self.part);
1331    }
1332
1333    /// Only applies the builder if the test is true.
1334    #[must_use]
1335    pub fn if_then<F>(self, test: bool, build: F) -> Self
1336    where
1337        F: Fn(Self) -> Self,
1338    {
1339        if test {
1340            build(self)
1341        } else {
1342            self
1343        }
1344    }
1345
1346    /// If the number:decimal-places attribute is not specified, the number of decimal places
1347    /// specified by the default table cell style is used.
1348    #[must_use]
1349    pub fn decimal_places(mut self, decimal_places: u8) -> Self {
1350        self.part
1351            .set_attr("number:decimal-places", decimal_places.to_string());
1352        self
1353    }
1354
1355    /// The number:style attribute specifies whether the content of a time element is displayed in short
1356    /// or long format. The value of this attribute can be short or long. The meaning of these values
1357    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1358    /// or time style.
1359    #[must_use]
1360    pub fn long_style(mut self) -> Self {
1361        self.part.set_attr("number:style", "long".to_string());
1362        self
1363    }
1364
1365    /// The number:style attribute specifies whether the content of a time element is displayed in short
1366    /// or long format. The value of this attribute can be short or long. The meaning of these values
1367    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1368    /// or time style.
1369    #[must_use]
1370    pub fn short_style(mut self) -> Self {
1371        self.part.set_attr("number:style", "short".to_string());
1372        self
1373    }
1374
1375    /// The number:style attribute specifies whether the content of a time element is displayed in short
1376    /// or long format. The value of this attribute can be short or long. The meaning of these values
1377    /// depends on the value of the number:format-source 19.348 attribute that is attached to a date
1378    /// or time style.
1379    #[must_use]
1380    pub fn style(mut self, style: FormatNumberStyle) -> Self {
1381        self.part.set_attr("number:style", style.to_string());
1382        self
1383    }
1384}
1385
1386/// Adds a format part to this format.
1387///
1388/// The number:am-pm element specifies whether AM/PM is included as part of a date or time.
1389/// If a number:am-pm element is contained in a date or time style, hours are displayed using
1390/// values from 1 to 12 only.
1391///
1392/// Can be used with ValueTypes:
1393/// * DateTime
1394/// * TimeDuration
1395#[derive(Debug)]
1396pub struct PartAmPmBuilder<'vf, T: ValueFormatTrait> {
1397    part: FormatPart,
1398    valueformat: &'vf mut T,
1399}
1400
1401impl<'vf, T: ValueFormatTrait> PartAmPmBuilder<'vf, T> {
1402    /// New builder for the valueformat.
1403    pub fn new<'a>(valueformat: &'a mut T) -> Self
1404    where
1405        'a: 'vf,
1406    {
1407        Self {
1408            part: FormatPart::new(FormatPartType::AmPm),
1409            valueformat,
1410        }
1411    }
1412
1413    /// Appends the constructed FormatPart to the original value format.
1414    pub fn build(self) {
1415        self.valueformat.push_part(self.part);
1416    }
1417}
1418
1419/// Adds a format part to this format.
1420///
1421/// The number:boolean element marks the position of the Boolean value of a Boolean style.
1422///
1423/// Can be used with ValueTypes:
1424/// * Boolean
1425#[derive(Debug)]
1426pub struct PartBooleanBuilder<'vf, T: ValueFormatTrait> {
1427    part: FormatPart,
1428    valueformat: &'vf mut T,
1429}
1430
1431impl<'vf, T: ValueFormatTrait> PartBooleanBuilder<'vf, T> {
1432    /// New builder for the valueformat.
1433    pub fn new<'a>(valueformat: &'a mut T) -> Self
1434    where
1435        'a: 'vf,
1436    {
1437        Self {
1438            part: FormatPart::new(FormatPartType::Boolean),
1439            valueformat,
1440        }
1441    }
1442
1443    /// Appends the constructed FormatPart to the original value format.
1444    pub fn build(self) {
1445        self.valueformat.push_part(self.part);
1446    }
1447}
1448
1449/// Adds a format part to this format.
1450///
1451/// The number:text element contains any fixed text for a data style.
1452///
1453/// Can be used with ValueTypes:
1454/// * Boolean
1455/// * Currency
1456/// * DateTime
1457/// * Number
1458/// * Percentage
1459/// * Text
1460/// * TimeDuration
1461#[derive(Debug)]
1462pub struct PartTextBuilder<'vf, T: ValueFormatTrait> {
1463    part: FormatPart,
1464    valueformat: &'vf mut T,
1465}
1466
1467impl<'vf, T: ValueFormatTrait> PartTextBuilder<'vf, T> {
1468    /// New builder for the valueformat.
1469    pub fn new<'a>(valueformat: &'a mut T) -> Self
1470    where
1471        'a: 'vf,
1472    {
1473        Self {
1474            part: FormatPart::new(FormatPartType::Text),
1475            valueformat,
1476        }
1477    }
1478
1479    /// Appends the constructed FormatPart to the original value format.
1480    pub fn build(self) {
1481        self.valueformat.push_part(self.part);
1482    }
1483
1484    /// Only applies the builder if the test is true.
1485    #[must_use]
1486    pub fn if_then<F>(self, test: bool, build: F) -> Self
1487    where
1488        F: Fn(Self) -> Self,
1489    {
1490        if test {
1491            build(self)
1492        } else {
1493            self
1494        }
1495    }
1496
1497    /// Sets the text value.
1498    #[must_use]
1499    pub fn text<S: Into<String>>(mut self, txt: S) -> Self {
1500        self.part.set_content(txt.into());
1501        self
1502    }
1503}
1504
1505/// Adds a format part to this format.
1506///    
1507/// The number:text-content element marks the position of variable text content of a text
1508/// style.
1509///
1510/// Can be used with ValueTypes:
1511/// * Text
1512
1513#[derive(Debug)]
1514pub struct PartTextContentBuilder<'vf, T: ValueFormatTrait> {
1515    part: FormatPart,
1516    valueformat: &'vf mut T,
1517}
1518
1519impl<'vf, T: ValueFormatTrait> PartTextContentBuilder<'vf, T> {
1520    /// New builder for the valueformat.
1521    pub fn new<'a>(valueformat: &'a mut T) -> Self
1522    where
1523        'a: 'vf,
1524    {
1525        Self {
1526            part: FormatPart::new(FormatPartType::TextContent),
1527            valueformat,
1528        }
1529    }
1530
1531    /// Appends the constructed FormatPart to the original value format.
1532    pub fn build(self) {
1533        self.valueformat.push_part(self.part);
1534    }
1535}