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

moonbitlang / x / 301

10 Dec 2024 06:19AM UTC coverage: 85.204% (-2.6%) from 87.841%
301

Pull #78

github

web-flow
Merge b830031f4 into 91f0fdf48
Pull Request #78: feat: new package encoding

105 of 161 new or added lines in 3 files covered. (65.22%)

124 existing lines in 29 files now uncovered.

1169 of 1372 relevant lines covered (85.2%)

434.92 hits per line

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

87.5
/time/zone.mbt
1
// Copyright 2024 International Digital Economy Academy
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
///| Time zone.
16
struct Zone {
17
  id : String
18
  offsets : Array[ZoneOffset]
19
  // TODO: offset transition rules
20
} derive(Eq)
21

22
///| UTC time zone.
23
pub let utc_zone : Zone = { id: "UTC", offsets: [utc_offset] }
24

25
///| Creates a time zone with fixed offset from time zone id and offset seconds.
26
pub fn fixed_zone(id : String, offset_seconds : Int) -> Zone!Error {
27
  let offset = ZoneOffset::from_seconds!(offset_seconds)
27✔
28
  Zone::{ id, offsets: [offset] }
27✔
29
}
30

31
///| Checks if this zone only has one offset.
32
pub fn is_fixed(self : Zone) -> Bool {
33
  self.offsets.length() == 1
45✔
34
}
35

36
///| Returns the zone id.
37
pub fn to_string(self : Zone) -> String {
38
  self.id
24✔
39
}
40

41
///|
42
pub impl Show for Zone with output(self : Zone, logger : Logger) -> Unit {
43
  logger.write_string(self.to_string())
3✔
44
}
45

46
///|
47
fn lookup_offset(self : Zone, _secs : Int64) -> ZoneOffset {
48
  if self.offsets.length() == 0 {
44✔
UNCOV
49
    return utc_offset
×
50
  }
51
  if self.is_fixed() {
52
    return self.offsets[0]
44✔
53
  }
54
  // TODO: lookup the offset by the seconds elapsed from unix epoch and the offset transition rules
55
  self.offsets[0]
56
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc