diff options
| author | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2009-08-26 15:13:41 +0000 |
|---|---|---|
| committer | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2009-08-26 15:13:41 +0000 |
| commit | de375da682cb7e5f9d00952f941628a588f1d2cc (patch) | |
| tree | b4c0e25f2ee3c494a4b3e56789bb6a1b8cc39758 | |
| parent | 667a1448cd95929d9e94f885d1a1e17097637a18 (diff) | |
| download | lasso-de375da682cb7e5f9d00952f941628a588f1d2cc.tar.gz lasso-de375da682cb7e5f9d00952f941628a588f1d2cc.tar.xz lasso-de375da682cb7e5f9d00952f941628a588f1d2cc.zip | |
XML: Add time formatting function for ISO 8601 format
* xml/private.h:
* xml/tools.c:
add util function to format time_t values in the ISO 8601 format.
| -rw-r--r-- | lasso/xml/private.h | 1 | ||||
| -rw-r--r-- | lasso/xml/tools.c | 25 |
2 files changed, 19 insertions, 7 deletions
diff --git a/lasso/xml/private.h b/lasso/xml/private.h index 9cabcb14..82460eb3 100644 --- a/lasso/xml/private.h +++ b/lasso/xml/private.h @@ -113,6 +113,7 @@ typedef enum { void lasso_build_random_sequence(char *buffer, unsigned int size); char* lasso_build_unique_id(unsigned int size); char* lasso_get_current_time(void); +char* lasso_time_to_iso_8601_gmt(time_t now); LassoPemFileType lasso_get_pem_file_type(const char *file); xmlSecKeyPtr lasso_get_public_key_from_pem_file(const char *file); diff --git a/lasso/xml/tools.c b/lasso/xml/tools.c index 1796daa7..d31e0a7b 100644 --- a/lasso/xml/tools.c +++ b/lasso/xml/tools.c @@ -120,26 +120,37 @@ lasso_build_unique_id(unsigned int size) } /** - * lasso_get_current_time: + * lasso_time_to_iso_8601_gmt: + * @now: a #time_t value * - * Returns the current time, format is "yyyy-mm-ddThh:mm:ssZ". + * Format the given time as an ISO 8601 date-time value in UTC. * - * Return value: a string - **/ + * Return value: an ISO 9601 formatted string. + */ char* -lasso_get_current_time() +lasso_time_to_iso_8601_gmt(time_t now) { - time_t now; struct tm *tm; char *ret; ret = g_malloc(21); - now = time(NULL); tm = gmtime(&now); strftime(ret, 21, "%Y-%m-%dT%H:%M:%SZ", tm); return ret; } +/** + * lasso_get_current_time: + * + * Returns the current time, format is "yyyy-mm-ddThh:mm:ssZ". + * + * Return value: a string + **/ +char* +lasso_get_current_time() +{ + return lasso_time_to_iso_8601_gmt(time(NULL)); +} /** * lasso_get_pem_file_type: |
