• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wger-project / flutter / 30854254088

03 Aug 2026 09:21PM UTC coverage: 40.895% (-15.0%) from 55.93%
30854254088

Pull #1260

github

web-flow
Merge d93794de5 into e3affdd4f
Pull Request #1260: WIP: health sync

9980 of 24404 relevant lines covered (40.89%)

1.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/lib/core/json.dart
1
/*
2
 * This file is part of wger Workout Manager <https://github.com/wger-project>.
3
 * Copyright (c)  2025 wger Team
4
 *
5
 * wger Workout Manager is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Affero General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Affero General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Affero General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18

19
import 'package:flutter/material.dart';
20
import 'package:intl/intl.dart';
21

22
num stringToNum(String? e) {
2✔
23
  return e == null ? 0 : num.parse(e);
2✔
24
}
25

26
num? stringToNumNull(String? e) {
3✔
27
  return e == null ? null : num.parse(e);
3✔
28
}
29

30
num stringOrIntToNum(dynamic e) {
1✔
31
  if (e is int) {
1✔
32
    return e.toDouble(); // Convert int to double (a type of num)
1✔
33
  }
34
  return num.tryParse(e) ?? 0;
1✔
35
}
36

37
String? numToString(num? e) {
×
38
  if (e == null) {
39
    return null;
40
  }
41

42
  return e.toString();
×
43
}
44

45
/*
46
 * Converts a datetime to ISO8601 date format, but only the date.
47
 * Needed e.g. when the wger api only expects a date and no time information.
48
 */
49
String? dateToYYYYMMDD(DateTime? dateTime) {
1✔
50
  if (dateTime == null) {
51
    return null;
52
  }
53
  return DateFormat('yyyy-MM-dd').format(dateTime);
2✔
54
}
55

56
/// Convert a date to UTC and then to an ISO8601 string.
57
///
58
/// This makes sure that the serialized data has correct timezone information.
59
/// Otherwise the django backend will possibly treat the date as local time,
60
/// which will not be correct in most cases.
61
String dateToUtcIso8601(DateTime dateTime) {
1✔
62
  return dateTime.toUtc().toIso8601String();
2✔
63
}
64

65
/// Converts an ISO8601 datetime string in UTC to a local DateTime object.
66
///
67
/// Needs to be used in conjunction with [dateToUtcIso8601] in the models to
68
/// correctly handle timezones.
69
DateTime utcIso8601ToLocalDate(String dateTime) {
1✔
70
  return DateTime.parse(dateTime).toLocal();
2✔
71
}
72

73
DateTime? utcIso8601ToLocalDateNull(String? dateTime) {
×
74
  if (dateTime == null) {
75
    return null;
76
  }
77

78
  return utcIso8601ToLocalDate(dateTime);
×
79
}
80

81
/*
82
 * Converts a time to a date object.
83
 * Needed e.g. when the wger api only sends a time but no date information.
84
 */
85
TimeOfDay stringToTime(String? time) {
1✔
86
  time ??= '00:00';
87
  return TimeOfDay.fromDateTime(DateTime.parse('2020-01-01 $time'));
3✔
88
}
89

90
TimeOfDay? stringToTimeNull(String? time) {
×
91
  if (time == null) {
92
    return null;
93
  }
94

95
  return TimeOfDay.fromDateTime(DateTime.parse('2020-01-01 $time'));
×
96
}
97

98
/*
99
 * Converts a datetime to time.
100
 */
101
String? timeToString(TimeOfDay? time) {
1✔
102
  if (time == null) {
103
    return null;
104
  }
105
  return const DefaultMaterialLocalizations().formatTimeOfDay(time, alwaysUse24HourFormat: true);
1✔
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc