LoginSignup
4
1

More than 5 years have passed since last update.

【令和】新元号対応に関するMicrosoft Win32等の時限措置に関する検証について

Last updated at Posted at 2019-04-14

時限措置

経済産業省公開文書で、4月限定の時限措置に関する記載があります。

改元に伴う元号による年表示の取扱いについて(平成31年4月1日新元号への円滑な移行に向けた関係省庁連絡会議申合せ)
https://www.meti.go.jp/policy/it_policy/kaigen/20190402_kaigen_2.pdf

(3)元号法第1項に基づく政令の公布後の取扱い 元号法(昭和 54 年法律第 43 号)第1項に基づく政令の公布日か ら施行日前までの間において、各府省が作成し公にする文書に元号 を用いて改元日以降の年を表示する場合は、「平成」を用いるもの とする

こちらについて、Microsoftの3/18のセミナーでは不確定情報として対応を検討するような話が出ていました。
https://qiita.com/tfukumori/items/1dc60eb473eff5efb994/revisions/110

検証

Win32のAPIを参照するDelphiの環境で、この時限措置が適用されたのかは不明ですが、システム日時が5月にならないと新元号が表示されないという問題がでた、という記事がありました。

【令和】Microsoft の元号対応が迷走している件 | Qiita

Win32、VBA、VB6、Microsoft.VisualBasic.Compatibility.VB6.Formatにもかかわる問題と思われるので、oleaut32.dllを直接呼び出して検証してみることにしました。

(4/14追記) 上記記事コメントにて @ht_deko さんに教えていただきましたが、影響を受けたAPIは、datetimeapi.h ヘッダー のGetDateFormatA 関数などのようです。詳細は上記記事コメントをご参照ください。

環境

Windows 10 1809 (OSビルド 17763.437)
https://support.microsoft.com/ja-jp/help/4493509/windows-10-update-kb4493509

image.png

image.png

image.png

レジストリ

image.png
image.png

コード

Class1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Class1
    {
        private static class NativeMethods
        {
            [DllImport("oleaut32.dll", CharSet = CharSet.Unicode)]
            internal static extern int VarFormat(ref object expr,
                    string format,
                    int firstDay,
                    int firstWeek,
                    int flags,
                    [MarshalAs(UnmanagedType.BStr)] out string result);

        }

        public static string Vb6Format(object expr, string format)
        {
            string result;
            int hr = NativeMethods.VarFormat(ref expr, format, 0, 0, 0, out result);
            if (hr != 0) throw new COMException("Format error", hr);
            return result;
        }
    }
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var d = DateTime.Parse("2019/5/1");
            Console.WriteLine( Class1.Vb6Format(d, "gggee年mm月dd日"));
            Console.ReadLine();
        }
    }
}

結果

結果としては、直接oleaut32.dllを呼び出した場合には、システム日付が4月でも、時限措置が適用されず、新元号が表示される形となりました。

令和01年05月01日

image.png

4
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1