Skip to content
Merged
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
10 changes: 6 additions & 4 deletions src/builder/create_poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct CreatePollMedia {
pub struct CreatePoll<Stage: Sealed> {
question: CreatePollMedia,
answers: Vec<CreatePollAnswer>,
duration: u8,
duration: u16,
allow_multiselect: bool,
layout_type: Option<PollLayoutType>,

Expand All @@ -51,7 +51,7 @@ impl Default for CreatePoll<NeedsQuestion> {
text: String::default(),
},
answers: Vec::default(),
duration: u8::default(),
duration: u16::default(),
allow_multiselect: false,
layout_type: None,

Expand Down Expand Up @@ -115,14 +115,16 @@ impl CreatePoll<NeedsAnswers> {
impl CreatePoll<NeedsDuration> {
/// Sets the duration for the Poll to run for.
///
/// This must be less than a week, and will be rounded to hours towards zero.
/// This must be at most 32 days, and will be rounded to hours towards zero.
pub fn duration(self, duration: std::time::Duration) -> CreatePoll<Ready> {
const DAYS_32: u16 = 768;

let hours = duration.as_secs() / 3600;

CreatePoll {
question: self.question,
answers: self.answers,
duration: hours.try_into().unwrap_or(168),
duration: hours.try_into().unwrap_or(DAYS_32),
allow_multiselect: self.allow_multiselect,
layout_type: self.layout_type,
_stage: Ready,
Expand Down
Loading