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

Use colon : for timezone layout when parsing dates #2322

Closed
JammingBen opened this issue Dec 3, 2021 · 5 comments · Fixed by #2744
Closed

Use colon : for timezone layout when parsing dates #2322

JammingBen opened this issue Dec 3, 2021 · 5 comments · Fixed by #2744
Labels
bug Something isn't working junior-job Easy issues

Comments

@JammingBen
Copy link

The ParseTimestamp() method currently uses 2006-01-02T15:04:05Z0700 as layout for parsing dates. This is somewhat inconsistent and suboptimal for oC Web, we'd rather expect 2006-01-02T15:04:05Z07:00 as the layout already uses delimiters like - and :.

Is there a chance to align that? Otherwise we would need to implement a custom format in oC Web as well.

parsedTime, err := time.Parse("2006-01-02T15:04:05Z0700", timestampString)

@refs
Copy link
Member

refs commented Dec 6, 2021

Could we use UTC offset instead of Zulu? Other than that I agree we should stick to a format, as both [hh][mm] and [hh]:[mm] are valid 👍

@JammingBen
Copy link
Author

Could we use UTC offset instead of Zulu?

Sure 👍

@refs
Copy link
Member

refs commented Dec 7, 2021

Actually I'm wrong. This is how UTC is defined in ISO 8601 😅 we just need to agree in a format. This issue should be a ticket for the fast-lane.

@JammingBen
Copy link
Author

[hh]:[mm] (-> 2006-01-02T15:04:05Z07:00) would be great for OcWeb as mentioned above 🙂

@refs refs added the bug Something isn't working label Dec 10, 2021
@butonic
Copy link
Contributor

butonic commented Jan 28, 2022

the oc10 code does this:

https://github.com/owncloud/core/blob/0dadfbe475438dd97c192cb93643ef8d95b71faa/apps/files_sharing/lib/Controller/Share20OcsController.php#L1155-L1179

	/**
	 * Make sure that the passed date is valid ISO 8601
	 * So YYYY-MM-DD
	 * If not throw an exception
	 *
	 * @param string $expireDate
	 *
	 * @throws Exception
	 * @return \DateTime
	 */
	private function parseDate($expireDate) {
		try {
			$date = new \DateTime($expireDate);
		} catch (Exception $e) {
			throw new Exception('Invalid date. Format must be YYYY-MM-DD');
		}

		if ($date === false) {
			throw new Exception('Invalid date. Format must be YYYY-MM-DD');
		}

		$date->setTime(0, 0, 0);

		return $date;
	}

So it seems to rely on PHP magic detection of the format and ignores the time / sets it to 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working junior-job Easy issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants