diff options
| author | 2025-05-13 18:34:32 +0200 | |
|---|---|---|
| committer | 2025-05-13 18:34:32 +0200 | |
| commit | cb76e4da84c61609c13e84c922f14a27b8348a36 (patch) | |
| tree | 6f0057efd11780ec38da6e8b686726f51bd10f30 /include | |
| parent | d7fe479707af57aeedf7e41c08e7fb698cd2e2a3 (diff) | |
| download | libplist-cb76e4da84c61609c13e84c922f14a27b8348a36.tar.gz libplist-cb76e4da84c61609c13e84c922f14a27b8348a36.tar.bz2 | |
Add plist_new_unix_date, plist_get_unix_date_val, plist_set_unix_date_val functions
These functions work with int64_t values representing a UNIX timestamp instead
of using the 'MAC epoch'. They should be used instead of plist_new_date,
plist_get_date_val, and plist_set_date_val, which are now marked deprecated
and might be removed in a future version of libplist.
Diffstat (limited to 'include')
| -rw-r--r-- | include/plist/Date.h | 6 | ||||
| -rw-r--r-- | include/plist/plist.h | 84 |
2 files changed, 74 insertions, 16 deletions
diff --git a/include/plist/Date.h b/include/plist/Date.h index 5113cf3..7026699 100644 --- a/include/plist/Date.h +++ b/include/plist/Date.h | |||
| @@ -40,13 +40,13 @@ public : | |||
| 40 | Date(plist_t node, Node* parent = NULL); | 40 | Date(plist_t node, Node* parent = NULL); |
| 41 | Date(const Date& d); | 41 | Date(const Date& d); |
| 42 | Date& operator=(const Date& d); | 42 | Date& operator=(const Date& d); |
| 43 | Date(timeval t); | 43 | Date(int64_t t); |
| 44 | virtual ~Date(); | 44 | virtual ~Date(); |
| 45 | 45 | ||
| 46 | Node* Clone() const; | 46 | Node* Clone() const; |
| 47 | 47 | ||
| 48 | void SetValue(timeval t); | 48 | void SetValue(int64_t t); |
| 49 | timeval GetValue() const; | 49 | int64_t GetValue() const; |
| 50 | }; | 50 | }; |
| 51 | 51 | ||
| 52 | }; | 52 | }; |
diff --git a/include/plist/plist.h b/include/plist/plist.h index aff81e9..41af8ce 100644 --- a/include/plist/plist.h +++ b/include/plist/plist.h | |||
| @@ -263,12 +263,11 @@ extern "C" | |||
| 263 | /** | 263 | /** |
| 264 | * Create a new plist_t type #PLIST_DATE | 264 | * Create a new plist_t type #PLIST_DATE |
| 265 | * | 265 | * |
| 266 | * @param sec the number of seconds since 01/01/2001 | 266 | * @param sec The number of seconds since 01/01/1970 (UNIX timestamp) |
| 267 | * @param usec the number of microseconds | ||
| 268 | * @return the created item | 267 | * @return the created item |
| 269 | * @sa #plist_type | 268 | * @sa #plist_type |
| 270 | */ | 269 | */ |
| 271 | PLIST_API plist_t plist_new_date(int32_t sec, int32_t usec); | 270 | PLIST_API plist_t plist_new_unix_date(int64_t sec); |
| 272 | 271 | ||
| 273 | /** | 272 | /** |
| 274 | * Create a new plist_t type #PLIST_UID | 273 | * Create a new plist_t type #PLIST_UID |
| @@ -775,10 +774,9 @@ extern "C" | |||
| 775 | * This function does nothing if node is not of type #PLIST_DATE | 774 | * This function does nothing if node is not of type #PLIST_DATE |
| 776 | * | 775 | * |
| 777 | * @param node the node | 776 | * @param node the node |
| 778 | * @param sec a pointer to an int32_t variable. Represents the number of seconds since 01/01/2001. | 777 | * @param sec a pointer to an int64_t variable. Represents the number of seconds since 01/01/1970 (UNIX timestamp). |
| 779 | * @param usec a pointer to an int32_t variable. Represents the number of microseconds | ||
| 780 | */ | 778 | */ |
| 781 | PLIST_API void plist_get_date_val(plist_t node, int32_t * sec, int32_t * usec); | 779 | PLIST_API void plist_get_unix_date_val(plist_t node, int64_t *sec); |
| 782 | 780 | ||
| 783 | /** | 781 | /** |
| 784 | * Get the value of a #PLIST_UID node. | 782 | * Get the value of a #PLIST_UID node. |
| @@ -867,10 +865,9 @@ extern "C" | |||
| 867 | * Forces type of node to #PLIST_DATE | 865 | * Forces type of node to #PLIST_DATE |
| 868 | * | 866 | * |
| 869 | * @param node the node | 867 | * @param node the node |
| 870 | * @param sec the number of seconds since 01/01/2001 | 868 | * @param sec the number of seconds since 01/01/1970 (UNIX timestamp) |
| 871 | * @param usec the number of microseconds | ||
| 872 | */ | 869 | */ |
| 873 | PLIST_API void plist_set_date_val(plist_t node, int32_t sec, int32_t usec); | 870 | PLIST_API void plist_set_unix_date_val(plist_t node, int64_t sec); |
| 874 | 871 | ||
| 875 | /** | 872 | /** |
| 876 | * Set the value of a node. | 873 | * Set the value of a node. |
| @@ -1213,16 +1210,15 @@ extern "C" | |||
| 1213 | 1210 | ||
| 1214 | /** | 1211 | /** |
| 1215 | * Helper function to compare the value of a PLIST_DATE node against | 1212 | * Helper function to compare the value of a PLIST_DATE node against |
| 1216 | * a given set of seconds and fraction of a second since epoch. | 1213 | * a given number of seconds since epoch (UNIX timestamp). |
| 1217 | * | 1214 | * |
| 1218 | * @param datenode node of type PLIST_DATE | 1215 | * @param datenode node of type PLIST_DATE |
| 1219 | * @param cmpsec number of seconds since epoch to compare against | 1216 | * @param cmpval Number of seconds to compare against (UNIX timestamp) |
| 1220 | * @param cmpusec fraction of a second in microseconds to compare against | ||
| 1221 | * @return 0 if the node's date is equal to the supplied values, | 1217 | * @return 0 if the node's date is equal to the supplied values, |
| 1222 | * 1 if the node's date is greater than the supplied values, | 1218 | * 1 if the node's date is greater than the supplied values, |
| 1223 | * or -1 if the node's date is less than the supplied values. | 1219 | * or -1 if the node's date is less than the supplied values. |
| 1224 | */ | 1220 | */ |
| 1225 | PLIST_API int plist_date_val_compare(plist_t datenode, int32_t cmpsec, int32_t cmpusec); | 1221 | PLIST_API int plist_unix_date_val_compare(plist_t datenode, int64_t cmpval); |
| 1226 | 1222 | ||
| 1227 | /** | 1223 | /** |
| 1228 | * Helper function to compare the value of a PLIST_STRING node against | 1224 | * Helper function to compare the value of a PLIST_STRING node against |
| @@ -1382,6 +1378,68 @@ extern "C" | |||
| 1382 | */ | 1378 | */ |
| 1383 | PLIST_API const char* libplist_version(); | 1379 | PLIST_API const char* libplist_version(); |
| 1384 | 1380 | ||
| 1381 | |||
| 1382 | /******************************************** | ||
| 1383 | * * | ||
| 1384 | * Deprecated API * | ||
| 1385 | * * | ||
| 1386 | ********************************************/ | ||
| 1387 | |||
| 1388 | /** | ||
| 1389 | * Create a new plist_t type #PLIST_DATE | ||
| 1390 | * | ||
| 1391 | * @deprecated Deprecated. Use plist_new_unix_date instead. | ||
| 1392 | * | ||
| 1393 | * @param sec the number of seconds since 01/01/2001 | ||
| 1394 | * @param usec the number of microseconds | ||
| 1395 | * @return the created item | ||
| 1396 | * @sa #plist_type | ||
| 1397 | */ | ||
| 1398 | PLIST_WARN_DEPRECATED("use plist_new_unix_date instead") | ||
| 1399 | PLIST_API plist_t plist_new_date(int32_t sec, int32_t usec); | ||
| 1400 | |||
| 1401 | /** | ||
| 1402 | * Get the value of a #PLIST_DATE node. | ||
| 1403 | * This function does nothing if node is not of type #PLIST_DATE | ||
| 1404 | * | ||
| 1405 | * @deprecated Deprecated. Use plist_get_unix_date_val instead. | ||
| 1406 | * | ||
| 1407 | * @param node the node | ||
| 1408 | * @param sec a pointer to an int32_t variable. Represents the number of seconds since 01/01/2001. | ||
| 1409 | * @param usec a pointer to an int32_t variable. Represents the number of microseconds | ||
| 1410 | */ | ||
| 1411 | PLIST_WARN_DEPRECATED("use plist_get_unix_date_val instead") | ||
| 1412 | PLIST_API void plist_get_date_val(plist_t node, int32_t * sec, int32_t * usec); | ||
| 1413 | |||
| 1414 | /** | ||
| 1415 | * Set the value of a node. | ||
| 1416 | * Forces type of node to #PLIST_DATE | ||
| 1417 | * | ||
| 1418 | * @deprecated Deprecated. Use plist_set_unix_date_val instead. | ||
| 1419 | * | ||
| 1420 | * @param node the node | ||
| 1421 | * @param sec the number of seconds since 01/01/2001 | ||
| 1422 | * @param usec the number of microseconds | ||
| 1423 | */ | ||
| 1424 | PLIST_WARN_DEPRECATED("use plist_set_unix_date_val instead") | ||
| 1425 | PLIST_API void plist_set_date_val(plist_t node, int32_t sec, int32_t usec); | ||
| 1426 | |||
| 1427 | /** | ||
| 1428 | * Helper function to compare the value of a PLIST_DATE node against | ||
| 1429 | * a given set of seconds and fraction of a second since epoch. | ||
| 1430 | * | ||
| 1431 | * @deprecated Deprecated. Use plist_unix_date_val_compare instead. | ||
| 1432 | * | ||
| 1433 | * @param datenode node of type PLIST_DATE | ||
| 1434 | * @param cmpsec number of seconds since epoch to compare against | ||
| 1435 | * @param cmpusec fraction of a second in microseconds to compare against | ||
| 1436 | * @return 0 if the node's date is equal to the supplied values, | ||
| 1437 | * 1 if the node's date is greater than the supplied values, | ||
| 1438 | * or -1 if the node's date is less than the supplied values. | ||
| 1439 | */ | ||
| 1440 | PLIST_WARN_DEPRECATED("use plist_unix_date_val_compare instead") | ||
| 1441 | PLIST_API int plist_date_val_compare(plist_t datenode, int32_t cmpsec, int32_t cmpusec); | ||
| 1442 | |||
| 1385 | /*@}*/ | 1443 | /*@}*/ |
| 1386 | 1444 | ||
| 1387 | #ifdef __cplusplus | 1445 | #ifdef __cplusplus |
