Skip to content

Commit

Permalink
Properly format BIOS date from WMI
Browse files Browse the repository at this point in the history
BIOS date retrieved from WMI are in the following
format: 20050927******.******+***

According to Microsoft:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394077(v=vs.85).aspx

Release date of the Windows BIOS in the Coordinated Universal Time (UTC)
format of YYYYMMDDHHMMSS.MMMMMMOOO.

Thank you Arnaud for the details.

closes: #1820

Reported-by: Arnaud Meurou <ameurou@live.fr>
  • Loading branch information
Gonéri Le Bouder committed Nov 2, 2012
1 parent da70e1a commit b6fbcb9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
16 changes: 13 additions & 3 deletions lib/FusionInventory/Agent/Task/Inventory/Input/Win32/Bios.pm
Expand Up @@ -15,17 +15,27 @@ sub isEnabled {
return 1;
}

sub _dateFromIntString {
my ($string) = @_;

if ($string && $string =~ /^(\d{4})(\d{2})(\d{2})/) {
return "$2/$3/$1";
}

return $string;
}

sub doInventory {
my (%params) = @_;

my $inventory = $params{inventory};
my $logger = $params{logger};

my $bios = {
BDATE => getRegistryValue(
BDATE => _dateFromIntString(getRegistryValue(
path => "HKEY_LOCAL_MACHINE/Hardware/Description/System/BIOS/BIOSReleaseDate",
logger => $logger
)
))
};

foreach my $object (getWmiObjects(
Expand All @@ -40,7 +50,7 @@ sub doInventory {
$bios->{BVERSION} = $object->{SMBIOSBIOSVersion} ||
$object->{BIOSVersion} ||
$object->{Version};
$bios->{BDATE} = $object->{ReleaseDate};
$bios->{BDATE} = _dateFromIntString($object->{ReleaseDate});
}

foreach my $object (getWmiObjects(
Expand Down
2 changes: 1 addition & 1 deletion lib/FusionInventory/Agent/Task/Inventory/Inventory.pm
Expand Up @@ -533,7 +533,7 @@ System Serial number
=item BDATE
BIOS release date
BIOS release date in the Month/Day/Year format (e.g: 09/27/2010)
=item BVERSION
Expand Down
31 changes: 31 additions & 0 deletions t/inventory/windows/bios.t
@@ -0,0 +1,31 @@
#!/usr/bin/perl

use strict;
use warnings;
use utf8;
use lib 't';

use English qw(-no_match_vars);
use Test::More;
use Test::MockModule;

use FusionInventory::Test::Utils;

BEGIN {
# use mock modules for non-available ones
push @INC, 't/fake/windows' if $OSNAME ne 'MSWin32';
}

use FusionInventory::Agent::Task::Inventory::Input::Win32::Bios;

my %tests = (
"20050927******.******+***" => "09/27/2005",
"foobar" => "foobar"
);
plan tests => scalar keys %tests;

foreach my $input (keys %tests) {
my $result = $tests{$input};

ok(FusionInventory::Agent::Task::Inventory::Input::Win32::Bios::_dateFromIntString($input) eq $result, "_dateFromIntString($input)");
}

0 comments on commit b6fbcb9

Please sign in to comment.