@@ -50,7 +50,7 @@ static LY_ERR
5050lyplg_type_store_date_and_time (const struct ly_ctx * ctx , const struct lysc_type * type , const void * value , uint64_t value_size_bits ,
5151 uint32_t options , LY_VALUE_FORMAT format , void * UNUSED (prefix_data ), uint32_t hints ,
5252 const struct lysc_node * UNUSED (ctx_node ), struct lyd_value * storage , struct lys_glob_unres * UNUSED (unres ),
53- struct ly_err_item * * err )
53+ ly_bool old_rev , struct ly_err_item * * err )
5454{
5555 LY_ERR ret = LY_SUCCESS ;
5656 struct lyd_value_date_and_time * val ;
@@ -120,7 +120,7 @@ lyplg_type_store_date_and_time(const struct ly_ctx *ctx, const struct lysc_type
120120 goto cleanup ;
121121 }
122122
123- if (!strncmp (((char * )value + value_size ) - 6 , "-00:00" , 6 ) || ((( char * )value )[value_size - 1 ] == 'Z' )) {
123+ if (!strncmp (((char * )value + value_size ) - 6 , "-00:00" , 6 ) || (! old_rev && ((( char * )value )[value_size - 1 ] == 'Z' ) )) {
124124 /* unknown timezone, timezone format supported for backwards compatibility */
125125 val -> unknown_tz = 1 ;
126126 }
@@ -148,6 +148,24 @@ lyplg_type_store_date_and_time(const struct ly_ctx *ctx, const struct lysc_type
148148 return ret ;
149149}
150150
151+ static LY_ERR
152+ lyplg_type_store_date_and_time_old (const struct ly_ctx * ctx , const struct lysc_type * type , const void * value ,
153+ uint64_t value_size_bits , uint32_t options , LY_VALUE_FORMAT format , void * prefix_data , uint32_t hints ,
154+ const struct lysc_node * ctx_node , struct lyd_value * storage , struct lys_glob_unres * unres , struct ly_err_item * * err )
155+ {
156+ return lyplg_type_store_date_and_time (ctx , type , value , value_size_bits , options , format , prefix_data , hints ,
157+ ctx_node , storage , unres , 1 , err );
158+ }
159+
160+ static LY_ERR
161+ lyplg_type_store_date_and_time_new (const struct ly_ctx * ctx , const struct lysc_type * type , const void * value ,
162+ uint64_t value_size_bits , uint32_t options , LY_VALUE_FORMAT format , void * prefix_data , uint32_t hints ,
163+ const struct lysc_node * ctx_node , struct lyd_value * storage , struct lys_glob_unres * unres , struct ly_err_item * * err )
164+ {
165+ return lyplg_type_store_date_and_time (ctx , type , value , value_size_bits , options , format , prefix_data , hints ,
166+ ctx_node , storage , unres , 0 , err );
167+ }
168+
151169/**
152170 * @brief Implementation of ::lyplg_type_compare_clb for ietf-yang-types date-and-time type.
153171 */
@@ -263,7 +281,7 @@ lyplg_type_sort_date_and_time(const struct ly_ctx *UNUSED(ctx), const struct lyd
263281 */
264282static const void *
265283lyplg_type_print_date_and_time (const struct ly_ctx * ctx , const struct lyd_value * value , LY_VALUE_FORMAT format ,
266- void * UNUSED (prefix_data ), ly_bool * dynamic , uint64_t * value_size_bits )
284+ void * UNUSED (prefix_data ), ly_bool old_rev , ly_bool * dynamic , uint64_t * value_size_bits )
267285{
268286 struct lyd_value_date_and_time * val ;
269287 struct tm tm ;
@@ -303,9 +321,9 @@ lyplg_type_print_date_and_time(const struct ly_ctx *ctx, const struct lyd_value
303321 return NULL ;
304322 }
305323
306- if (asprintf (& ret , "%04d-%02d-%02dT%02d:%02d:%02d%s%sZ " ,
324+ if (asprintf (& ret , "%04d-%02d-%02dT%02d:%02d:%02d%s%s%s " ,
307325 tm .tm_year + 1900 , tm .tm_mon + 1 , tm .tm_mday , tm .tm_hour , tm .tm_min , tm .tm_sec ,
308- val -> fractions_s ? "." : "" , val -> fractions_s ? val -> fractions_s : "" ) == -1 ) {
326+ val -> fractions_s ? "." : "" , val -> fractions_s ? val -> fractions_s : "" , old_rev ? "-00:00" : "Z" ) == -1 ) {
309327 return NULL ;
310328 }
311329 } else {
@@ -331,6 +349,20 @@ lyplg_type_print_date_and_time(const struct ly_ctx *ctx, const struct lyd_value
331349 return value -> _canonical ;
332350}
333351
352+ static const void *
353+ lyplg_type_print_date_and_time_old (const struct ly_ctx * ctx , const struct lyd_value * value , LY_VALUE_FORMAT format ,
354+ void * prefix_data , ly_bool * dynamic , uint64_t * value_size_bits )
355+ {
356+ return lyplg_type_print_date_and_time (ctx , value , format , prefix_data , 1 , dynamic , value_size_bits );
357+ }
358+
359+ static const void *
360+ lyplg_type_print_date_and_time_new (const struct ly_ctx * ctx , const struct lyd_value * value , LY_VALUE_FORMAT format ,
361+ void * prefix_data , ly_bool * dynamic , uint64_t * value_size_bits )
362+ {
363+ return lyplg_type_print_date_and_time (ctx , value , format , prefix_data , 0 , dynamic , value_size_bits );
364+ }
365+
334366/**
335367 * @brief Implementation of ::lyplg_type_dup_clb for ietf-yang-types date-and-time type.
336368 */
@@ -395,19 +427,35 @@ lyplg_type_free_date_and_time(const struct ly_ctx *ctx, struct lyd_value *value)
395427 * LYPLG_TYPES = {
396428 */
397429const struct lyplg_type_record plugins_date_and_time [] = {
430+ {
431+ .module = "ietf-yang-types" ,
432+ .revision = "2013-07-15" ,
433+ .name = "date-and-time" ,
434+
435+ .plugin .id = "ly2 date-and-time" ,
436+ .plugin .lyb_size = lyplg_type_lyb_size_variable_bytes ,
437+ .plugin .store = lyplg_type_store_date_and_time_old ,
438+ .plugin .validate_value = NULL ,
439+ .plugin .validate_tree = NULL ,
440+ .plugin .compare = lyplg_type_compare_date_and_time ,
441+ .plugin .sort = lyplg_type_sort_date_and_time ,
442+ .plugin .print = lyplg_type_print_date_and_time_old ,
443+ .plugin .duplicate = lyplg_type_dup_date_and_time ,
444+ .plugin .free = lyplg_type_free_date_and_time ,
445+ },
398446 {
399447 .module = "ietf-yang-types" ,
400448 .revision = "2025-12-22" ,
401449 .name = "date-and-time" ,
402450
403451 .plugin .id = "ly2 date-and-time" ,
404452 .plugin .lyb_size = lyplg_type_lyb_size_variable_bytes ,
405- .plugin .store = lyplg_type_store_date_and_time ,
453+ .plugin .store = lyplg_type_store_date_and_time_new ,
406454 .plugin .validate_value = NULL ,
407455 .plugin .validate_tree = NULL ,
408456 .plugin .compare = lyplg_type_compare_date_and_time ,
409457 .plugin .sort = lyplg_type_sort_date_and_time ,
410- .plugin .print = lyplg_type_print_date_and_time ,
458+ .plugin .print = lyplg_type_print_date_and_time_new ,
411459 .plugin .duplicate = lyplg_type_dup_date_and_time ,
412460 .plugin .free = lyplg_type_free_date_and_time ,
413461 },
0 commit comments