Skip to content
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

parse timezone parameter in mysql connection url #3418

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions sqlx-mysql/src/options/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ impl MySqlConnectOptions {
options = options.socket(&*value);
}

"timezone" | "time-zone" => {
options = options.timezone(Some(value.to_string()));
}

_ => {}
}
}
Expand Down Expand Up @@ -176,3 +180,16 @@ fn it_returns_the_parsed_url() {

assert_eq!(expected_url, opts.build_url());
}

#[test]
fn it_parses_timezone() {
let opts: MySqlConnectOptions = "mysql://user:password@hostname/database?timezone=%2B08:00"
.parse()
.unwrap();
assert_eq!(opts.timezone.as_deref(), Some("+08:00"));

let opts: MySqlConnectOptions = "mysql://user:password@hostname/database?time-zone=%2B08:00"
.parse()
.unwrap();
assert_eq!(opts.timezone.as_deref(), Some("+08:00"));
}